Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Apr 10, 2024
1 parent 3797eee commit d6e316c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
13 changes: 7 additions & 6 deletions src/zippy/ziparchives.nim
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,13 @@ proc createZipArchive*(
result.add(path)

# result.add(compressed)
result.setLen(result.len + compressed.len)
copyMem(
result[result.len - compressed.len].addr,
compressed.cstring,
compressed.len
)
if compressed != "":
result.setLen(result.len + compressed.len)
copyMem(
result[result.len - compressed.len].addr,
compressed.cstring,
compressed.len
)

result.add32(dataDescriptorSignature)
result.add32(uncompressedCrc32)
Expand Down
42 changes: 25 additions & 17 deletions tests/test_ziparchives_write.nim
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import std/os, zippy/ziparchives, std/tables
import std/os, zippy/ziparchives, std/tables, std/strutils

var entries: OrderedTable[string, string]
entries["a/b/tmp.txt"] = "a text file's contents here"
# var entries: OrderedTable[string, string]
# entries["a/b/tmp.txt"] = "a text file's contents here"

let archive = createZipArchive(entries)
echo archive.len
writeFile("tmp.zip", archive)
# let archive = createZipArchive(entries)
# echo archive.len
# writeFile("tmp.zip", archive)

let reader = openZipArchive("tmp.zip")
# let reader = openZipArchive("tmp.zip")

try:
# Iterate over the paths in the zip archive.
for path in reader.walkFiles:
echo path
# try:
# # Iterate over the paths in the zip archive.
# for path in reader.walkFiles:
# echo path

# # Extract a file from the archive.
let contents = reader.extractFile("a/b/tmp.txt")
echo contents.len
finally:
# Remember to close the reader when done.
reader.close()
# # # Extract a file from the archive.
# let contents = reader.extractFile("a/b/tmp.txt")
# echo contents.len
# finally:
# # Remember to close the reader when done.
# reader.close()

# var entries: OrderedTable[string, string]
# for path in walkDirRec(getCurrentDir(), relative = true, skipSpecial = true):
# if path.startsWith(".git"):
# continue
# if path.endsWith(".exe"):
# continue
# entries[path] = readFile(path)
# writeFile("tmp.zip", createZipArchive(entries))

0 comments on commit d6e316c

Please sign in to comment.