I implemented the gzip/zlib decompression of files as shown in their examples on the boost site.
void CompressionUtils::Inflate(std::ifstream& inputFile,
std::ofstream& outputFile)
{
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(inputFile);
boost::iostreams::copy(in, outputFile);
}
this works fine. I am also reading data from a socket that I am getting from a rest based JSON service that is compressed as well. I figured I would write a memory based implementation, how hard could that be. Well, I figured out I do not understand the streams and stream buffers as I should. I blame the last few years in Java ;) .. So I started down this path.
void CompressionUtils::Inflate(char* compressed,
int size,
char* decompressed)
{
boost::iostreams::stream<boost::iostreams::array_source> source(compressed,size);
//std::stringstream str;
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(source);
//boost::iostreams::copy(in, str);
}
But I am at a loss as to what kind of stream I can use to basically get the decompressed char*
representation of the decompressed stream. This should be easy, and probably is, but I have been wasting the last couple hours coming up with unsuccessful attempts.