拥有带有一些数据的 stringstream 如何以跨平台方式对其进行 gzip ?
所以我们有一些带有一些数据的字符串流。借助哪个跨平台库,我们可以将其内容转换为 gzip 格式(您可以将其保存到扩展名为 .tar.gz 的文件中)
让我们进入代码:所以我有:
stringstream body;
body << std::ifstream( path.string().c_str(), ios::binary).rdbuf();
我应该添加哪些内容,我应该调用哪个函数编码 stringstream 以及调用哪个函数来将编码数据放入 stringstream 中?
顺便说一句:有没有可以编码成 gzip 的 boost 库
So we have some stringstream with somedata. With help of which cross platform library we can turn its contents into gziped format (you would 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提升。iostreams 具有对 bzip2 和 gzip 压缩/解压缩。
boost.iostreams has optional built-in support for bzip2 and gzip compression/decompression.
不太清楚你在问什么。如果你的意思是
文件(由
path
指定)是 gzipped 格式,最简单解决方案可能是定义一个管道输入流,并读取它
来自
gunzip <通过该文件
。如果你想解压它在您的应用程序中,某种过滤输入流缓冲区
看起来是有序的(参见 boost::iostream)。
无论如何我都不会使用临时
std::ifstream
:你想要在尝试读取之前验证打开是否成功。
It's not too clear what you're asking. If you mean that the
file (specified by
path
) is in gzipped format, the easiestsolution is probably to define a pipe input stream, and read it
from
gunzip < file
through that. If you want to unzip itwithin 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: youwant to verify that the open succeeded before trying to read.