EDIT: This is now “haydxn’s Juce Archive Format Blog” - tracking the development of the ZipFile based archive classes, which should provide a neat all-purpose method of storing any amount of any kind of data.
[16-12-07] Changed format to the altogether-more-flexible ‘ZipOutputStream’. Download ZipOutputStream.h
EXCITING UPDATE! w00t!
Compression now works!
While Juce has good support for reading zip files, it’s been noted several times that you can’t make them yourself with it. So, I knocked together a simple class to do just that.
Now we have a means of creating a file with multiple data types embedded [e.g. XML document data + images, all in one package]. I’d like to expand on it, making a wrapper for such ‘combination’ file formats.
Here it is: Download ZipFileMaker.zip - this archive created using ZipFileMaker.
It’s really straightforward to use:
- Create a ZipFileMaker (on the stack will do)
- Call addFile() for any files you wish to add. If you want a file to be nested in subfolders in the zip, simply use a path in the storedFilename parameter
[e.g. “images/image1.jpg” ]. The compressionLevel parameter lets you specify how much to squash the file; 0 is uncompressed, else 1-9 from least to most compressed.
- Call createOutputFile() when you’re done.
And that’s it! To prove it, here is the code that I used to create the zip file you just downloaded… (of course i only used literal paths for quick testing purposes!)
ZipFileMaker zipper; zipper.addFile (File(T("C:/ZipFileMaker.h")),9); zipper.addFile (File(T("C:/ZipFileMaker.cpp")),9); zipper.addFile (File(T("C:/ZipOutputStream.h")),9); zipper.addFile (File(T("C:/ZipOutputStream.cpp")),9); zipper.createOutputFile (File(T("C:/ZipFileMaker.zip")),true);
[note] This will have problems if trying to write to a volume that doesn’t allow seeking in the output stream. I’ve not had any experience with that yet, but perhaps USB (or networked) drives may have such limitations. It’s possible to write the header data in a different way to get around this, but that’s really beyond what I could be bothered with! Feel free to add support for this if you’re willing (you’d need to read up on the zip spec - it involves placing additional data AFTER the entry content; there should at least be a clue in the .cpp file).
Alternatively of course (if it is a problem for you), you could just create the output zip file in a temp location on a normal drive, and copy it to the troublesome volume when done.