Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 295
Daniel Stefanovski Avatar asked Mar 28 '11 16:03

Daniel Stefanovski


1 Answers

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);
like image 51
Daniel Stefanovski Avatar answered Nov 15 '22 12:11

Daniel Stefanovski