Deflate Compression Stream where pre compressed Data can be inserted. Does a .NET lib exist?

后端 未结 3 513
走了就别回头了
走了就别回头了 2021-01-15 04:14

I\'m implementing Deflate and GZip compression for web content. The .NET Framework DeflateStream performs very well (it doesn\'t compress that good as SharpZipLib, but it is

相关标签:
3条回答
  • 2021-01-15 04:48

    Another approach is to flush the deflater stream (and possibly also close it), to guarantee that all buffered compressed data is written to the output stream, and then simply write your precompressed data to the underlying output stream, then re-open the deflater stream on top of your output stream again.

    0 讨论(0)
  • 2021-01-15 04:58

    Yes, you can insert precompressed blocks in to a zlib stream. Start with the zpipe.c example in the zlib source. Only where you want to insert your precompressed block, replace Z_NO_FLUSH with Z_FULL_FLUSH (otherwise don't use Z_FULL_FLUSH because the compression ratio will suffer.)

    Now the compressed output is byte aligned and the last deflate block is closed. Full flush means that the next block past the precompressed block cannot contain any back references.

    Append your precompressed block to the output stream (e.g. memcpy). Advance strm.next_out to the next empty byte. Continue with deflate where you left off.

    flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
    ret = deflate(&strm, flush);
    
    0 讨论(0)
  • 2021-01-15 05:00

    IIRC the #ZipLib allows you to set the compression level, have you tried flushing the stream and dropping the level to 0 and then sending the already compressed data before raising the compression level again?

    If you are only looking at doing this for performance reasons then this might be an acceptable solution.

    0 讨论(0)
提交回复
热议问题