Boost :: iostream zlib compresses multiple files into one archive

I had a problem packing multiple files into one archive. accelerated documents are very limited on this topic, and I searched the website several times, but I cannot find a solution.

What I still have:

boost::filesystem::ofstream ofsArchive("some.zip"); boost::iostreams::filtering_ostreambuf outFilter; boost::iostreams::zlib_params zparam(boost::iostreams::zlib::default_compression); try { // set up the filter outFilter.strict_sync(); outFilter.push(boost::iostreams::zlib_compressor(zparam)); outFilter.push(ofsArchive); for(each object of some kind) { // create a binary serialized file boost::filesystem::ofstream ofs(filename, std::ios_base::binary); boost::archive::binary_oarchive bin_oa( ofs ); bin_oa << crazyObject; // here where i'm stuck. how to add multiple files to the "some.zip"? boost::iostreams::copy(ofs, outputArchive); } } catch(boost::iostreams::zlib_error& e){...} 

How to add files to a zip archive? the provided method obviously does not work, I just can not find anything on this subject in the documents or header files

+8
c ++ boost serialization compression zlib
source share
2 answers

zlib does not implement the Zip file format; it simply implements the stream compression used in Zip (see zlib FAQ ). As far as I know (that I should not warn you completely) Boost does not include functions for reading or writing Zip archives. There are libraries that really provide this functionality , for example, zziplib (note: the site seems to be at the bottom of the moment).

Edit: Obviously, zziplib cannot actually write Zip files, it can only read them. However, I'm sure a little googling will bring up a library capable of writing the format.

+4
source share

I know that the post is a little outdated, but for people like me who see this many years later.

There are tons of free librairies to write and read zip files in C (can be used in C ++, of course):
- infoZip (the latest version, apparently, is really complete and safe, although it dates back to 2008); - libzip , much later, the latest version is only two months old.

0
source share

All Articles