Hey! o/ I'm in need of making some archives and fo...
# announcements
t
Hey! o/ I'm in need of making some archives and for the sake of "universality" I decided to go with ZIP, and so I'm wondering if there's any nicer way than Java's zip module 😅 Thanks in advance!
g
https://github.com/zeroturnaround/zt-zip It’s a nice wrapper. Uses
java.util.zip
under the hood.
t
looks nice! will give it a try
@grahamborland your library looks nice but I was looking more for a way to pack some content (like some byte arrays) into a new byte array, instead of always doing file IO, since that would be kinda redundant as I'm preparing the zip to send via a Web api
g
There are examples of how to write to/from a stream rather than a file. You can use
ByteArrayOutputStream
instead of
FileOutputStream
in this example. https://github.com/zeroturnaround/zt-zip#add-an-entry-from-file-and-from-byte-array-to-a-output-stream
t
Oh I must have missed that 🤦
thanks
tho @grahamborland I just looked at it and that method implies I have an existing zip file already, which I don't have
ig I could just feed it an empty input stream?
g
It doesn’t imply that at all. It shows how you’d read from both a file and a byte array. If you don’t need the file input, don’t use that line of code.
Sorry, I didn’t notice that. I haven’t looked through all the examples in detail, but I assume there’s a way of doing what you want without an existing file.