filtering_streambuf: Compressing a character buffer

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

filtering_streambuf: Compressing a character buffer

Adlai Shawareb

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;
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?

Unsubscribe & other changes: