#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 sink; // Create compressing stream based on original input boost::iostreams::filtering_istreambuf compressingStream; compressingStream.push(boost::iostreams::bzip2_compressor()); compressingStream.push(boost::make_iterator_range(source)); // Create decompressing stream writing to sink boost::iostreams::filtering_ostreambuf decompressingStream; decompressingStream.push(boost::iostreams::bzip2_decompressor()); decompressingStream.push(boost::iostreams::back_inserter(sink)); try { // Compress and decompress boost::iostreams::copy(compressingStream, decompressingStream); // Show result cout << "Result after compression and subsequent de-compression: " << 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; } }