5

使用時に「zlib同期フラッシュ」を取得するために必要な魔法はありboost::iostreams::zlib_compressorますか?フィルターを呼び出すだけflush、またはフィルターstrict_syncfiltering_ostream含むものを呼び出すだけでは、ジョブは実行されません(つまり、ストリームを閉じずに、デコンプレッサーがこれまでにコンプレッサーによって消費されたすべてのバイトを回復できるように、コンプレッサーを十分にフラッシュする必要があります)。

ヘッダーを見ると、いくつかの「フラッシュコード」(特にsync_flush)が定義されているように見えますが、それらをどのように使用するかはわかりません(コンプレッサーがに追加されていることを念頭に置いてくださいfiltering_ostream)。

4

2 に答える 2

2

symmetric_filter継承元がそれ自体でフラッシュ可能ではないという 根本的な問題があることが判明しましたzlib_compressor(これはむしろ見落としのようです)。

おそらく、そのようなサポートをに追加するのは、既存のプライベートフラッシュメソッドsymmetric_filterを追加して公開するのと同じくらい簡単flushable_tagですが、今のところ私はそれで生きることができます。

于 2010-04-12T11:25:19.073 に答える
1

このC++zlibラッパーライブラリは、私が作成者であり、フラッシュ機能をサポートしており、ほぼ間違いなく簡単に使用できます。

https://github.com/rudi-cilibrasi/zlibcomplete

これと同じくらい簡単です:

#include <iostream>
#include <zlc/zlibcomplete.hpp>

using namespace zlibcomplete;
using namespace std;

int main(int argc, char **argv)
{
  const int CHUNK = 16384;
  char inbuf[CHUNK];
  int readBytes;
  ZLibCompressor compressor(9, auto_flush);
  for (;;) {
    cin.read(inbuf, CHUNK);
    readBytes = cin.gcount();
    if (readBytes == 0) {
      break;
    }
    string input(inbuf, readBytes);
    cout << compressor.compress(input);
  }
  cout << compressor.finish();
  return 0;
}

The main difference from boost is that instead of using a template class filter you simply pass in a string and write out the compressed string that results as many times as you want. Each string will be flushed (in auto_flush mode) so it can be used in interactive network protocols. At the end just call finish to get the last bit of compressed data and a termination block. While the boost example is shorter, it requires using two other template classes that are not as well-known as std::string, namely filtering_streambuf and the less-standard boost::iostreams:copy. The boost interface to zlib is incomplete in that it does not support Z_SYNC_FLUSH. This means it is not appropriate for online streaming applications such as in TCP interactive protocols. I love boost and use it as my main C++ support library in all of my C++ projects but in this particular case it was not usable in my application due to the missing flush functionality.

于 2015-07-08T19:12:28.170 に答える