The POCO Library requires an istream for input and ostream for output to compress data using its zlib wrapper. I have data in a std::vector(unsigned char) and would like to compress this data into another std::vector(unsigned char). Is there any easy way to do this?
The POCO Library requires an istream for input and ostream for output to compress
Share
I don’t know that this is the most efficient way, but as a start I’d try this:
I suspect this copies the data twice, unnecessarily. First, the call to ostringstream::str() makes a copy, and next std::vector::assign() makes a copy.
@Alf P. Steinbach had an excellent suggestion — use Boost stream adapters. If you have
boost::iostreams::filtering_ostreamavailable to you, you could try this: