2
我必須處理用gzip壓縮的大文件。我需要訪問行的一個子集,不一定按順序。因此,我想在我感興趣的線路上記錄流位置時,一次遍歷所有文件。然後,使用這些流位置快速檢索我需要的信息。我使用gzstream。但不幸的是tellg
似乎不使用此包裝工作:如何在使用gzstream和gzip文件時保持流位置?
#include <iostream>
#include <fstream>
using namespace std;
#include <gzstream.h>
int main (int argc, char ** argv)
{
string inFile;
string line;
system ("rm -f infile1.txt; echo \"toto1\ntoto2\ntoto3\" > infile1.txt");
inFile = "infile1.txt";
ifstream inStream;
inStream.open (inFile.c_str());
cout << inStream.tellg() << endl;
getline (inStream, line);
cout << inStream.tellg() << endl;
inStream.close();
system ("rm -f infile1.gz; echo \"toto1\ntoto2\ntoto3\" | gzip > infile1.gz");
inFile = "infile1.gz";
igzstream igzStream;
igzStream.open (inFile.c_str());
cout << igzStream.tellg() << endl;
getline (igzStream, line);
cout << igzStream.tellg() << endl;
igzStream.close();
return 0;
}
此代碼返回此:
$ gcc -Wall test.cpp -lstdc++ -lgzstream -lz
$ ./a.out
0
6
18446744073709551615
18446744073709551615
有沒有一種方法,使與igzstream這項工作?或者我應該用Boost gzip filters代替?任何代碼片段將不勝感激;)
謝謝。的確,提供變體壓縮格式(變體但非常接近gzip)的答案非常有用。更詳細的答案可以在這裏找到:http://biostar.stackexchange.com/questions/13627/random-access-of-lines-in-a-compressed-file-having-a-custom-tabulated-format/15098# 15098 – tflutre