ファイルを解凍してその内容をストリングストリームに書きたいとします。圧縮されていないfiltering_istreamをストリングストリームにコピーしようとするとクラッシュします
これは私が試したコードです:実行中
string readGZipLog() {
try {
using namespace boost::iostreams;
ifstream file(currentFile.c_str(), std::ios_base::in | std::ios_base::binary);
boost::iostreams::filtering_istream in;
in.push(gzip_decompressor());
in.push(file);
std::stringstream strstream;
boost::iostreams::copy(in, strstream);
return strstream.str();
} catch (std::exception& e) {
cout << e.what() << endl;
}
}
void writeGZipLog (char* data) {
try {
using namespace boost::iostreams;
std::ofstream file(currentFile.c_str(), std::ios_base::out | std::ios_base::binary);
boost::iostreams::filtering_ostream out;
out.push(gzip_compressor());
out.push(file);
std::stringstream strstream;
strstream << data;
boost::iostreams::copy(strstream, data);
} catch (std::exception& e) {
cout << e.what() << endl;
}
}
をそれは(そしてもちろんエラーの)警告なしでコンパイルが、関数readGZipLog()
クラッシュ:
gzip error
./build: line 3: 22174 Segmentation fault ./test
./build
は、そのスクリプトですコンパイルしてアプリケーションを自動的に開始する./test
Icファイルを聞いた:それは何かが含まれていますが、私はgunzip
を使用してungzipできません。だから私は圧縮が適切に機能しているかどうか、そしてこれがBoostによって投げられたgzip error
と関係があるかどうかはわかりません。
エラーが発生している箇所をヒットできますか?
ありがとうございました!
ポール