boost::filtering_streambuf 与 gzip_decompressor(),如何从文件中逐行访问
我写了一个Logparser应用程序,现在我想实现.gz文件的解压缩。我尝试使用 boost::iostreams 和 zlib 似乎可以工作,但我不知道如何处理从压缩文件中获得的输入。
这就是我所做的:
input.open(p.source_at(i).c_str(), ios_base::in | ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(input);
boost::iostreams::copy(in, cout);
如果我的源文件以 .gz 结尾,则运行此代码。最后一行将解压后的文件流正确输出到cout。
但如何从解压后的文件中逐行获取呢?我的程序使用 getline(input, transfer) 从输入流中读取行(如果未压缩)。
现在我想以同样的方式从解压缩的文件中读取内容,但是如何从中获取新行?
提升衰减对我来说没有多大帮助。
提前致谢!
I wrote a Logparser Application and now I want to implement decompression of .gz files. I tried it with boost::iostreams and zlib which seems to work, but I don't know how to handle the input I get from compressed files.
Here's what I do:
input.open(p.source_at(i).c_str(), ios_base::in | ios_base::binary);
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
in.push(boost::iostreams::gzip_decompressor());
in.push(input);
boost::iostreams::copy(in, cout);
This code is run, if my sourcefile has the .gz ending. The last line outputs the decompressed filestream correctly to cout.
But how can i fetch line by line from the decompressed file? My Program uses getline(input, transfer) to read lines from the input stream, if it's not compressed.
Now I want to read from the decompressed file the same way, but how can I get a new line from in?
The boost decumentation didn't help me much with this.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我发现了。我只需创建一个 std::istream 并传递对缓冲区的引用:
Ok I found it out. I just had to create an std::istream and pass a reference to the buffer: