How can I decompress a vector of deflated data with Boost?

情到浓时终转凉″ 提交于 2019-12-04 04:53:50

问题


I have a vector that contains zlib-compressed (deflated) data. I would like to decompress it with Boost's filtering_istream. There is only one example on their site, which operates on a stream of data (as opposed to a vector that I have).

vector<char> compressed_buffer;
compressed_buffer.resize(cdh.length);
file.read(&compressed_buffer[0], cdh.length);

filtering_istream in;
in.push(zlib_decompressor());
in.push(something(compressed_data)); // what should "something" be?

I would like to get the uncompressed data as a vector as well. How can I do this?


回答1:


How about an array_source?

in.push(array_source(&*compressed_data.begin(), &*compressed_data.end()));

Then use boost::iostreams::copy with a std::insert_iterator to push the result characters into a new vector.



来源:https://stackoverflow.com/questions/9557555/how-can-i-decompress-a-vector-of-deflated-data-with-boost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!