Decompression of the bzip2 byte array

How can I unzip bzip2 compressed bytes using boost? I found an example here , but the input file is a file, so ifstream used. The documentation is not very clear to me: (.

Edit: I will take alternatives to enhance.

+4
source share
1 answer

Here is my code using DEFLATE compression in boost.iostreams library; I am sure that you can connect the corresponding BZip2 compressor:

 #include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/filter/zlib.hpp> #include <boost/iostreams/filter/bzip2.hpp> // <--- this one for you #include <boost/iostreams/write.hpp> // Output std::ofstream datfile(filename, std::ios::binary); boost::iostreams::filtering_ostreambuf zdat; zdat.push(boost::iostreams::zlib_compressor()); // your compressor here zdat.push(datfile); boost::iostreams::write(zdat, BUFFER, BUFFER_SIZE); // Input std::ifstream datfile(filename, std::ios::binary); boost::iostreams::filtering_istreambuf zdat; zdat.push(boost::iostreams::zlib_decompressor()); zdat.push(datfile); boost::iostreams::read(zdat, BUFFER, BUFFER_SIZE); 

The bzip2 compressor is called bzip2_(de)compressor() .

If you need a byte buffer, not a file, use a line stream:

 char mydata[N]; std::string mydatastr(mydata, N); std::istringstream iss(mydatastr, std::ios::binary); std::ostringstream oss(mydatastr, std::ios::binary); 
+6
source

All Articles