私はgzippedで圧縮された大きなファイルを扱わなければなりません。私はラインのサブセットにアクセスする必要がありますが、必ずしもそうではありません。このように、私は興味のある行にストリームの位置を記録しながら、一度すべてのファイルを調べることを考えていました。そして、これらのストリームの位置を使用して、必要な情報をすばやく取得します。gzstreamをgzippedファイルで使用する場合のストリームの位置を保持する方法は?
このため、gzstreamを使用しています。しかし残念ながらtellg
はこのラッパーで動作していないよう:
#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