boost gzip_compressor and gzip_decompressor
boost, c++, gzip
Solution
I've found out a way of this problem. Here is the working code.
Compressing part
std::string compressedString;
{
filtering_ostream compressingStream;
compressingStream.push(boost::iostreams::gzip_compressor(gzip_params(gzip::best_compression)));
compressingStream.push(boost::iostreams::back_inserter(compressedString));
compressingStream << stringToBeCompressed;
boost::iostreams::close(compressingStream);
}
Decompressing part
std::string decompressedString;
{
boost::iostreams::filtering_ostream decompressingStream;
decompressingStream.push(boost::iostreams::gzip_decompressor());
decompressingStream.push(boost::iostreams::back_inserter(decompressedString));
decompressingStream << stringToBeDecompressed;
boost::iostreams::close(decompressingStream);
}
Problem
I'm using `boost`'s `gzip_compressor` and 'gzip_decompressor' for compressing some string. I'm compressing string like this ``` string compressedString; { filtering_ostream out; out.push(gzip_compressor(gzip_params(gzip::best_compression))); out.push(boost::iostreams::back_inserter(compressedString)); out.write(stringToBeCompressed.c_str(), stringToBeCompressed.size()); } ``` It works fine, but I can't to decompress it. Here is my code ``` std::string decompressedString; { filtering_ostream out; out.push(gzip_decompressor()); out.push(boost::iostreams::back_inserter(decompressedString)); out.write(compressedString.c_str(), compressedString.size()); } ``` What am I doing wrong? Thank you in advance!