@chrisname:
That is kind of funny. I've looked at libarchive before... and it's one of those libs that I referred to before... functional, but I cant stand the interface.
The goal with the lib I'm working on is to make the fact that the file is in an archive completely transparent. I do this by abstracting the file system into a class, and using inheritance to create other "filesystems"... treating each archive like they're their own filesystem.
The interface ends up being like this:
1 2 3 4 5 6 7 8 9 10
|
// 'fs' is a global object to access the disk file system.
auto zip = fs.openArchive("myzip.zip"); // open an archive
// here, you can iterate over files/directories, rename/copy/create/delete files
// and directories in 'zip' just as you could in the 'fs' global file system.
//
// And also open new files just as you would in the global FS:
auto file = zip->openFile("path/to/myfile.xxx");
// file would have read/write/etc functions just as a normal file would.
| |
That's it. Write to the file and the changes will be recompressed and saved upon exit (though from your program's perspective, they'll appear to be saved immediately -- if you open the file again it will remember the changes).
It works by caching the extracted files in temporary files on disk. Then when the archive is closed, it just goes through all the cached files and rebuilds the zip from them.
I'm actually very close to done with it. Everything is working except for 2 key parts:
- Copying files between file systems
- Actually saving the .zip file =P (though that's not as big of a job as it sounds)
I eventually plan to create wrappers for SFML's InputStream class and possibly even std::iostream. I also want to add a "mount" feature that allows you to treat an archive like a path name. So you could do this:
1 2 3
|
fs.mount("path/to/myzip.zip"); // mount the zip to make it "just another directory"
file = fs.openFile("path/to/myzip.zip/file.xxx"); // opens a file from the zip
| |
This would just be syntax sugar though... so I'm going to finish up the other stuff first. Though it would spare you the need of having to hang on to that 'zip' object.