4

私が扱っているファイルは大量の圧縮されていない(圧縮されていない100 GBの領域)ので、いわばその場で行ごとにいくつかの.bz2ファイルを解凍しようとしてきたので、保存するソリューションを追加したかったディスクスペース。

バニラbzip2で圧縮されたファイルを使用して解凍するのに問題はありませんが、pbzip2で圧縮されたファイルは、最初に見つかったbz2ストリームのみを解凍します。このバグトラッカーは問題に関連しています: https://svn.boost.org/trac/boost/ticket/3853しかし、バージョン 1.41 を過ぎて修正されたと信じるに至りました。bzip2.hpp ファイルを確認したところ、「修正済み」バージョンが含まれており、プログラムで使用されている Boost のバージョンが 1.59 であることも確認しました。

コードは次のとおりです。

cout<<"Warning bzip2 support is a little buggy!"<<endl;

//Open the file here
trans_file.open(files[i].c_str(), std::ios_base::in |  std::ios_base::binary);

//Set up boost bzip2 compression
boost::iostreams::filtering_istream in;
in.push(boost::iostreams::bzip2_decompressor());
in.push(trans_file);
std::string str;

//Begin reading
while(std::getline(in, str))
{
    std::stringstream stream(str);
    stream>>id_f>>id_i>>aif;
    /* Do stuff with values here*/
}

どんな提案も素晴らしいでしょう。ありがとう!

4

1 に答える 1

4

あなたが正しいです。

変更セット #63057 は問題の一部のみを修正しているようです。

ただし、対応する単体テストは機能します。ただし、copyアルゴリズムを使用します(関連する場合は、 a のcomposite<>代わりに afiltering_istreamでも)。

これを欠陥または回帰として開きます。もちろん、問題を示すファイルを含めてください。私にとっては、 (デフォルトオプション)で/etc/dictionaries-common/words圧縮しただけで再現されます。pbzip2

私はtest.bz2ここにいます:http://7f0d2fd2-af79-415c-ab60-033d3b494dc9.s3.amazonaws.com/test.bz2

これが私のテストプログラムです:

#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/stream.hpp>
#include <fstream>
#include <iostream>

namespace io = boost::iostreams;

void multiple_member_test(); // from the unit tests in changeset #63057

int main() {
    //multiple_member_test();
    //return 0;

    std::ifstream trans_file("test.bz2", std::ios::binary);

    //Set up boost bzip2 compression
    io::filtering_istream in;
    in.push(io::bzip2_decompressor());
    in.push(trans_file);

    //Begin reading
    std::string str;
    while(std::getline(in, str))
    {
        std::cout << str << "\n";
    }
}

#include <boost/iostreams/compose.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/device/back_inserter.hpp>
#include <cassert>
#include <sstream>

void multiple_member_test()  // from the unit tests in changeset #63057
{ 
    std::string      data(20ul << 20, '*');
    std::vector<char>  temp, dest; 

    // Write compressed data to temp, twice in succession 
    io::filtering_ostream out; 
    out.push(io::bzip2_compressor()); 
    out.push(io::back_inserter(temp)); 
    io::copy(boost::make_iterator_range(data), out); 
    out.push(io::back_inserter(temp)); 
    io::copy(boost::make_iterator_range(data), out); 

    // Read compressed data from temp into dest 
    io::filtering_istream in; 
    in.push(io::bzip2_decompressor()); 
    in.push(io::array_source(&temp[0], temp.size())); 
    io::copy(in, io::back_inserter(dest)); 

    // Check that dest consists of two copies of data 
    assert(data.size() * 2 == dest.size()); 
    assert(std::equal(data.begin(), data.end(), dest.begin())); 
    assert(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2)); 

    dest.clear(); 
    io::copy( 
            io::array_source(&temp[0], temp.size()), 
            io::compose(io::bzip2_decompressor(), io::back_inserter(dest))); 

    // Check that dest consists of two copies of data 
    assert(data.size() * 2 == dest.size()); 
    assert(std::equal(data.begin(), data.end(), dest.begin())); 
    assert(std::equal(data.begin(), data.end(), dest.begin() + dest.size() / 2)); 
} 
于 2015-09-30T19:25:46.827 に答える