How to use boost :: iostreams :: mapped_file_source with gzipped input file

I use boost :: iostreams :: mapped_file_source to read a text file from a specific position to a specific position and to control each line (compiled with g ++ -Wall -O3 -lboost_iostreams -o test main.cpp):

#include <iostream>
#include <string>
#include <boost/iostreams/device/mapped_file.hpp>

int main() {
    boost::iostreams::mapped_file_source f_read;
    f_read.open("in.txt");

    long long int alignment_offset(0);

    // set the start point
    const char* pt_current(f_read.data() + alignment_offset);
    // set the end point
    const char* pt_last(f_read.data() + f_read.size());
    const char* pt_current_line_start(pt_current);

    std::string buffer;

    while (pt_current && (pt_current != pt_last)) {
        if ((pt_current = static_cast<const char*>(memchr(pt_current, '\n', pt_last - pt_current)))) {
            buffer.assign(pt_current_line_start, pt_current - pt_current_line_start + 1);
            // do something with buffer

            pt_current++;
            pt_current_line_start = pt_current;
        }
    }

    return 0;
}

Currently, I would like to make this code a gzip file descriptor and modify the code as follows:

#include<iostream>
#include<boost/iostreams/device/mapped_file.hpp>
#include<boost/iostreams/filter/gzip.hpp>
#include<boost/iostreams/filtering_streambuf.hpp>
#include<boost/iostreams/filtering_stream.hpp>
#include<boost/iostreams/stream.hpp>

int main() {
    boost::iostreams::stream<boost::iostreams::mapped_file_source> file;
    file.open(boost::iostreams::mapped_file_source("in.txt.gz"));

    boost::iostreams::filtering_streambuf< boost::iostreams::input > in; 
    in.push(boost::iostreams::gzip_decompressor());
    in.push(file);

    std::istream std_str(&in);
    std::string buffer;
    while(1) {
        std::getline(std_str, buffer);
        if (std_str.eof()) break;
        // do something with buffer
    }   
}   

This code also works well, but I don't know how to set the start point (pt_current) and end point (pt_last) as the first code. Could you tell me how I can set two values ​​in the second code?

+4
source share
1 answer

: , . .


: ?. . / .

, , , .

, .

:


, , , ( ).

zran.c zlib, zlib:

28. ?

, . Z_FULL_FLUSH, , . , Z_FULL_FLUSH , . , , . . examples/zran.c

¹ , , , pbzip2 pigz; "" "" .

+2

All Articles