9

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!

4

1 回答 1

11

好的,我发现了。我只需要创建一个 std::istream 并将引用传递给缓冲区:

std::istream incoming(&in);
getline(incoming, transfer);
于 2011-03-28T20:46:04.603 回答