2016-05-19 9 views
0

私は時々データバッファを取得しているC++プログラムを持っており、それを既存の圧縮ファイルに追加する必要があります。膨大なデータストリームのデフレーション圧縮アルゴリズム

私は、あるファイルから1kチャンクを読み込み、圧縮されたストリームに渡して、POCを作成しようとしました。データがなくなったときに解凍しました。

私はPoco :: DeflatingOutputStreamを使用して各チャンクをファイルに圧縮し、Poco :: InflatingOutputStreamを使用して圧縮解除後に元のファイルを取得することを確認します。 à¿_ÿ

ここでの例です:

しかし、ストリームを解凍した後、私のデータは、データの2つの連続するチャンクの間、私のようないくつかの文字化けを取得することを除いて、元のファイルとほぼ同じに行ったようです2つのチャンクに分割されたライン。元の行は、そのようになります。

elevated=0 path=/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock exist 

減圧ラインであるのに対し:

elevated=0 path=/System/Libr à¿_ÿary/CoreServices/Dock.app/Contents/MacOS/Dock exist 

5月19日午前19時12分51秒PANMMUZNG8WNREMカーネル[0] = 0

PID = 904 UID = 1873876126 SBIT

私は間違っていると思います。ここに私のPOCコードです:

int zip_unzip() { 
    std::ostringstream stream1; 
    Poco::DeflatingOutputStream gzipper(stream1, Poco::DeflatingStreamBuf::STREAM_ZLIB); 

    std::ifstream bigFile("/tmp/in.log"); 
    constexpr size_t bufferSize = 1024; 
    char buffer[bufferSize]; 
    while (bigFile) { 
     bigFile.read(buffer, bufferSize); 
     gzipper << buffer; 
    } 
    gzipper.close(); 

    std::string zipped_string = stream1.str(); 
    ////////////////// 
    std::ofstream stream2("/tmp/out.log", std::ios::binary); 
    Poco::InflatingOutputStream gunzipper(stream2, InflatingStreamBuf::STREAM_ZLIB); 
    gunzipper << zipped_string; 
    gunzipper.close(); 
    return 0; 
} 

答えて

0

[OK]をヌル終端記号「/ 0がなかったことから、私はちょうど、私は気にせずにHugeFile(元解凍ファイル)から読み取った各上の「< <」演算子を使用し実現'私はファイルから読み取った各ウィンドウの最後に。

#include <stdio.h> 
#include <fstream> 
#include <Poco/DeflatingStream.h> 
#include <Poco/Exception.h> 
#include <iostream> 


int BetterZip() 
{ 
    try { 
    // Create gzip file. 
    std::ofstream output_file("/tmp/out.gz", std::ios::binary); 
    Poco::DeflatingOutputStream output_stream(output_file, Poco::DeflatingStreamBuf::STREAM_GZIP); 

    // INPUT 
    std::ifstream big_file("/tmp/hugeFile"); 
    constexpr size_t ReadBufferSize = 1024; 
    char buffer[ReadBufferSize]; 
    while (big_file) { 
     big_file.read(buffer, ReadBufferSize); 
     output_stream.write(buffer, big_file.gcount()); 
    } 

    output_stream.close(); 
    } catch (const Poco::Exception& ex) { 
     std::cout << "Error : (error code " << ex.code() << " (" << ex.displayText() << ")"; 
     return EINVAL; 
    } 

    return 0; 
} 
:固定バージョンです

関連する問題