I need to do some in-memory manipulation of strings, including compression to gzip format.  I am new to the use of Boost and to the use of gzip.  I found the following snippet on the Internet, compressing a std::string and producing a new std::string as output.  This implies that gzip_compressor never produces a null byte in its output but the gzip_compressor documentation doesn't say that and my search of the underlying library zlib documentation doesn't say anything like that either.  So is this a correct use?

 

std::string compress(const std::string& data)

{

    namespace bio = boost::iostreams;

 

    std::stringstream compressed;

    std::stringstream origin(data);

 

    bio::filtering_streambuf<bio::input> out;

    out.push(bio::gzip_compressor(bio::gzip_params(bio::gzip::best_compression)));

    out.push(origin);

    bio::copy(out, compressed);

 

    return compressed.str();

}

 

Thanks,

John Boncek