开发者

Having stringstream with some data how to gzip it cross platform way?

开发者 https://www.devze.com 2023-02-28 08:05 出处:网络
So we have some stringstream with somedata. With help of which cross platform library we can turn its contents into gzipedformat (you woul开发者_如何学Cd save it into file with extention .tar.gz)

So we have some stringstream with somedata. With help of which cross platform library we can turn its contents into gziped format (you woul开发者_如何学Cd save it into file with extention .tar.gz)

Lets get into code: so I have:

          stringstream body;
          body << std::ifstream( path.string().c_str(), ios::binary).rdbuf();

Which includes shall I add, which function should I call to encode stringstream and which finction to call to turn to put that encoded data into stringstream?

BTW: is there any boost library that can encode into gzip


boost.iostreams has optional built-in support for bzip2 and gzip compression/decompression.


It's not too clear what you're asking. If you mean that the file (specified by path) is in gzipped format, the easiest solution is probably to define a pipe input stream, and read it from gunzip < file through that. If you want to unzip it within your application, some sort of filtering input streambuf would seem in order (see boost::iostream).

And I wouldn't use a temporary std::ifstream in any case: you want to verify that the open succeeded before trying to read.

0

精彩评论

暂无评论...
验证码 换一张
取 消