boost::filtering_streambuf with gzip_decompressor(), how to access line by line from file
Asked Answered
A

1

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!

Autonomy answered 28/3, 2011 at 16:19 Comment(0)
A
12

Ok I found it out. I just had to create an std::istream and pass a reference to the buffer:

std::istream incoming(&in);
getline(incoming, transfer);
Autonomy answered 28/3, 2011 at 20:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.