5
votes

I wonder how DEFLATE determines block size(I mean, in zlib.)

In RFC 1591, following explanation exists: "The compressor terminates a block when it determines that starting a new block with fresh trees would be useful, or when the block size fills up the compressor's block buffer."

It is not enough for me. I want to know what condition is needed to end current block and start new block in detail.

How does DEFLATE decide whether fresh tress would be useful or not? What is size of compressor's block buffer?

1

1 Answers

7
votes

zlib's deflate ends the block when either the current symbol buffer fills up (by default 16,383 symbols), or the input data is complete (Z_FINISH was requested). deflate in zlib does not try to judge when it might be beneficial to end a block earlier.

One symbol in this case is either one literal, or one match of any length.

The size of the symbol buffer is determined by the memLevel parameter of deflateInit2(). A memLevel of 8, which is the default used by deflateInit(), results in 16,383 symbols. memLevel can be 1 to 9, where the symbol buffer size is (1 << (memLevel + 6)) - 1.