Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::iostream zlib compressing multiple files into one archive

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

like image 563
cppanda Avatar asked Feb 10 '11 18:02

cppanda


1 Answers

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.

like image 182
John Bartholomew Avatar answered Oct 21 '22 04:10

John Bartholomew