Zlib

zlib format is a container and extension of the DEFLATE compressed data format. It adds a lightweight container, a small amount of configurability, and error checking.

zlib is also the name of a software library that supports the zlib format, and other formats related to DEFLATE.

There are many formats and protocols that use, or may use, zlib format. A notable example is PNG.

Identification
The first two bytes can help to identify a zlib datastream. The following tests are ordered starting with those that are most certain to be true.


 * If the first two bytes are interpreted as a big-endian integer, it is always a multiple of 31. (Always true)
 * The first byte has eight possible values:,  ,  , ...,  . (Always true, unless the zlib format has been extended to support compression methods other than Deflate.)
 * Almost always, the  bit of the second byte is 0. (A value of 1 is legal in zlib v3.3+, but indicates use of a preset dictionary, so the zlib stream is not as portable.)
 * Most often, the Deflate window size is 32K, and there is no preset dictionary. With these assumptions, the first byte is, and the second is   (if using fastest compression),   (fast),   (default), or   (max), with   and   being the most common.

Specifications

 * ZLIB Specification v3.1 - No copy found. There are dead links to it in e.g. the zlib 0.95 README file.
 * ZLIB Specification v3.2 (from archive.org)
 * RFC 1950: ZLIB Compressed Data Format Specification version 3.3

Software

 * zlib data compression library
 * CloudFlare fork of zlib
 * zlib-ng
 * Puff - Lightweight decompression software included with zlib (contrib/puff)
 * miniz
 * zopfli - zlib compressor highly optimized for file size
 * Offzip

See also DEFLATE.

Links

 * Wikipedia article