Boost logo

Boost :

Subject: [boost] filtering_streambuf: Compressing a character buffer
From: Adlai Shawareb (adlai_at_[hidden])
Date: 2017-02-01 20:30:23


Hi,

I have a character buffer ( "buffer" ) of known size ( "size_in_bytes" ), and would like to compress it using gzip_compressor and then get a pointer to the compressed buffer along with the compressed size.

I've put together the following, but it says the first counter is 0 and the second counter is 2.

Any help that can be offered is appreciated.

namespace io = boost::iostreams;

boost::asio::streambuf sb;
std::ostream os(&sb);
os.write( buffer, size_in_bytes );

io::filtering_streambuf<boost::iostreams::output> out;
out.push(io::counter());
out.push(io::gzip_compressor());
out.push(io::counter());
out.push(os);
io::close(out); // Needed for flushing the data from compressor

std::ostream output(&out); // Maybe I can use rdbuf() to get the pointer to the stream?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk