Home > other >  ZLib: DeflatePrime number of bits of Z_PARTIAL_FLUSH
ZLib: DeflatePrime number of bits of Z_PARTIAL_FLUSH

Time:07-02

In the ZLIB Manual it is stated that Z_PARTIAL_FLUSH always flush an extra 10 bits. So that we correct for that using deflatePrime when we want to append later.

But why then is gzlog.c containing logic to find dynamically the bit count if *buf . According to the specs this is not needed and only the else is needed to set it to 10?

        if (*buf) {
            log->back = 1;
            while ((*buf & ((uint)1 << (8 - log->back  ))) == 0)
                ;       /* guaranteed to terminate, since *buf != 0 */
        }
        else
            log->back = 10;

CodePudding user response:

Because most of the time not all of the ten bits are written. Only in the case where the last byte is a zero are all ten bits written, because by chance (a one-in-eight chance) there were six bits pending to be written before the ten-bit empty static block.

  • Related