#include #include #include #include #pragma GCC visibility push(default) // required when compiling with g++ -fvisibility=hidden #include #pragma GCC visibility pop using namespace std; int main() { string source("Original"); string bzip2String; string sink; try { // Create compressing stream based on original input boost::iostreams::filtering_ostream compressingStream; compressingStream.push(boost::iostreams::bzip2_compressor()); compressingStream.push(boost::iostreams::back_inserter(bzip2String)); compressingStream << source; boost::iostreams::close(compressingStream); cerr << "size of bzip2String: " << bzip2String.size() << endl; // Create decompressing stream writing to sink boost::iostreams::filtering_ostream decompressingStream; decompressingStream.push(boost::iostreams::bzip2_decompressor()); decompressingStream.push(boost::iostreams::back_inserter(sink)); decompressingStream << bzip2String; boost::iostreams::close(decompressingStream); cerr << "Result: " << sink << endl; } catch(boost::iostreams::bzip2_error& error) { cerr << "Caught bzip2 error with code: " << error.error() << endl; cerr << "data_error: " << boost::iostreams::bzip2::data_error << endl; cerr << "data_error_magic: " << boost::iostreams::bzip2::data_error_magic << endl; cerr << "config_error: " << boost::iostreams::bzip2::config_error << endl; } }