Closed enthus1ast closed 3 months ago
This 100% makes sense. The current zip archive and tarball implementation is pretty basic, I mostly wanted to learn how they work and figured a basic thing is better than nothing. I now know how to do both much better and will be making improvements over time, including this option to get a zip archive blob without writing to disk.
Should i leave this issue open for documenting/referencing?
Yep that's fine, can use this for updates unless you'd prefer to close it.
For easiest changes without changing much the implementation is by changing writeZipArchive to $
(which returns string) or write
(name can be vary) which returns seq[uint8]
, change it to return the data
instead of directly writing it to file, and have the actual writeZipArchive
reuses it:
proc writeZipArchive*(archive: ZipArchive, path: string) =
path.writeFile($archive) # or path.writeFile(archive.write)
This way we still have the same writeZipArchive
works as is.
I had a need for this myself recently so I wrote a new zip archive writer that just returns the archive bytes as a string. See this example: https://github.com/guzba/zippy/blob/master/examples/ziparchive_create.nim
This is about as simple of an API I could come up with for a quick zip archive creater. It does mean many options are not possible, such as controlling file modified timestamps etc. But for many scenarios this simple creater should work very well.
It would be nice to have a procedure that just returns the binary of a zipfile instead of writing to disk.