Reset boost :: iostreams :: zlib_compressor. How to get "synchronization"?

Is there any magic needed to get a "zlib sync flush" when used boost::iostreams::zlib_compressor? Just calling flushin the filter or strict_syncon the filtering_ostreamone containing it does not see the job being completed (i.e. I want the compressor to be smooth enough so that the decompressor can recover all the bytes consumed by the compressor, so that it’s far without closing the stream).

Looking at the headline, it seems that some “flash codes” are defined (especially a sync_flush), but I don’t understand how they should be used (given that my compressor is just added to filtering_ostream).

+3
source share
2 answers

It turns out that there is a fundamental problem, which is that symmetric_filterwhat zlib_compressorinherits from not itself flushable (which seems more like supervision).

Perhaps adding such support to symmetric_filterwill be as simple as adding flushable_tagand publishing existing private cleaning methods, but for now I can live with it.

+1
source

This C ++ zlib cover library, of which I am the author, supports flash functionality and is probably easier to use:

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

It is so simple:

#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;
}

boost , , , . ( auto_flush), . , . , , std::string, filtering_streambuf boost:: iostreams: copy. boost zlib , Z_SYNC_FLUSH. , , TCP. ++ ++, - .

0

Source: https://habr.com/ru/post/1737492/


All Articles