How to implement compressed file bundles

How would you go about and implement documents as bundles of multiple files all inside one ZIP archive?

The idea is to include the actual document, a header file with metadata (for browsing & search), multiple snapshots/backups, etc. All based on compressed XML. At the file system level this should be a single file to keep things safely together (sharing). Individual files inside need to be accessible independently, i.e. the header/metadata must be readable without reading the entire bundle.

Has anyone successfully implemented this?

What part of the solution are you unclear about? Given that there is the existing ZipFile class, which gives you access to the directory contents of a zip file, and the ability to access individual entries of the zip file in memory with createStreamFor or on to disk with the uncompress___ functions?

I will have another look at the ZipFile class. I’m not sure if snapshots/backups can be added to or removed from an existing file without rebuilding the whole file. I may have missed that though.

Ah! You did not specify that you wanted to update it without rebuilding the whole file. I’m not sure what compressed format would support that. You only specified you wanted to read individual items from it without reading the whole thing.

Yeah, I mean being able to read a header with meta data w/o reading several MB of the actual document is already great. Both header + data wouldn’t be updated separately anyway. And XML mandates compression for large documents.

Merely the backups and snapshots would require a file bundle. Bundles are natively supported only on macOS. On Windows they simply fall apart and can’t easily be browsed either.

For the writing I would recommend the TemporaryFile approach, where it writes to a sibling file and swaps it then with the target file after finishing.

File bundles are just folders with a nice facade. MacOS will display them nicely, on all other OSses they appear like normal folders.