Search code examples
c++ziparchive

C++ file container (e.g. zip) for easy access


I have a lot of small files I need to ship with an application I build and I want to put this files into an archive to make copying and redistributing more easy. I also really like the idea of having them all in one place so I need to compare the md5 of one file only in case something goes wrong.

I'm thinking about a class which can load the archive and return a list of files within the archive and load a file into memory if I need to access it.

I already searched the Internet for different methods of achieving what I want and found out about zlib and the lzma sdk. Both didn't really appeal to me because I don't really found out how portable zlib is and I didn't like the lzma sdk as it is just to much and I don't want to blow up the application because of this problem. Another downside with zlib is that I don't have the C/C++ experience (I'm really new to C++) to get everything explained in the manual.

I also have to add that this is a time critical problem. I though some time about implementing a simple format like tar in a way I can easy access the files within my application but I just didn't find the time to do that yet.

So what I'm searching for is a library that allows me to access the files within an archive. I'd be glad if anybody could point me in the right direction here.

Thanks in advance, Robin.

Edit: I need the archive to be accessed under linux and windows. Sorry I didn't mention that in the beginning.


Solution

  • The answer depends on whether you plan to modify the archive via code after the archive is initially built.

    If you don't need to modify it, you can use TAR - it's a handy and simple format. If you want compression, you can implement tar.gz reader or find some library that does this (I believe there are some available, including open-source ones).

    If your application needs random access to the data or it needs to modify the archive, then regular TAR or ZIP archives are not good. Virtual file system such as our SolFS or CodeBase file system will fit much better: virtual file systems are suited for frequent modifications of the storage, while archives target mainly write-once-read-many usage scenarios.