i'm having trouble packing a bunch of files into one archive. the boost docs are very limited on this topic and i've searched the web for several hours now, but i can't find a solution.
What i have so far:
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's 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 do i add the files to the zip archive? the method provided obviously doesn't work, i just can't find anything on the subject in the docs or header files
zlib does not implement the Zip file format, it just implements the stream compression used within Zip (see the zlib FAQ). To my knowledge (which I should warn you is by no means total), Boost does not include functionality to read or write Zip archives. There are libraries that do provide that functionality of course, for example, zziplib (note: the site appears to be down at the moment).
Edit: Apparently, zziplib actually can't write Zip files, it can only read them. Still, I'm sure a little googling would turn up a library capable of writing the format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With