This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Zlib" – news ·newspapers ·books ·scholar ·JSTOR(March 2021) (Learn how and when to remove this message) |
| zlib (library) | |
|---|---|
| Developers | [1] |
| Initial release | 1 May 1995 (1995-05-01) |
| Stable release | |
| Written in | C |
| Operating system | Cross-platform |
| Type | Data compression |
| License | zlib License |
| Website | zlib |
| Repository | |
zlib (/ˈziːlɪb/ or "zeta-lib",/ˈziːtəˌlɪb/)[3][4] is a data format and alossless data compressionsoftware library created byJean-loup Gailly andMark Adler. The library implements theDeflate algorithm and supports compressing and decompressing data using thezlib data format, thegzip file format, or simply as aDeflate stream.[5]
zlib is also a crucial component of many software platforms, includingLinux,macOS, andiOS. It has also been used in gaming consoles such as thePlayStation 4,PlayStation 3,Wii U,Wii,Xbox One andXbox 360.[citation needed]
The first public version of Zlib, 0.9, was released on 1 May 1995 and was originally intended for use with thelibpng image library. It isfree software, distributed under thezlib License.
RFC 1950 specifies the zlib data format.[6]
| zlib (data format) | |
|---|---|
| Internet media type | application/zlib[7] |
| Size limitation | Unlimited |
| Developed by | [8] |
| Type of format | Data compression |
| Compression | Lossless |
| Container for | Deflate stream |
| Standard | RFC 1950 |
The zlib data format consists of a 2-byteheader, an optional extra header field, Deflate-compressed data, and a 4-bytetrailer.
Endianness isbig-endian.[9]Bit 0 is theleast significant bit in a byte.[10]
| Offset (bytes) | Field[11] | Size (bytes) | Description |
|---|---|---|---|
| 0 | CMF | 1 | This byte is divided into two 4-bit fields: |
| 1 | FLG | 1 |
|
| 2 | DICTID | 0 or 4 | Adler-32 checksum of thepreset DEFLATE dictionary used during compression. Present if theFDICT flag is set. The decompressor can use this checksum to determine which dictionary has been used by the compressor (e.g.inflateSetDictionary inzlib.h). |
| Varies | Compressed data | Varies | Deflate stream. |
| ADLER32 | 4 | Adler-32 checksum of theuncompressed data (excluding any dictionary data). |
Deflate compression typically uses the zlib data format or the gzip file format, which add a header and a trailer to the compressed data. This provides stream identification and error detection that are not provided by a Deflate stream.
The zlib format (at least 6 bytes) is smaller than the gzip format (at least 18 bytes) as the latter stores filesystem metadata.
As of September 2018[update], zlib only supports one algorithm, calledDEFLATE, which uses a combination of a variation of LZ77 (Lempel–Ziv 1977) andHuffman coding.[12] This algorithm provides good compression on a wide variety of data with minimal use of system resources. This is also the algorithm used in theZip archive format. The header makes allowance for other algorithms, but none are currently implemented.
zlib provides facilities for control of processor and memory use. A compression level value may be supplied that trades speed for compression. There are also facilities for conserving memory, useful in restricted memory environments, such as some embedded systems.
The compression can be optimized for specific types of data. If one is using the library to always compress specific types of data, then using a specific strategy may improve compression and performance. For example, if the data contain long lengths of repeated bytes, therun-length encoding (RLE) strategy may give good results at a higher speed. For general data, the default strategy is preferred.
Errors in compressed data may be detected and skipped. Further, if "full-flush" points are written to the compressed stream, then corrupt data can be skipped, and the decompression will resynchronize at the next flush point—although no error recovery of the corrupt data is provided. Full-flush points are useful for large data streams on unreliable channels, where somedata loss is unimportant, such as in some multimedia applications. However, creating many flush points can affect the speed as well as the amount (ratio) of compression.
There is no limit to the length of data that can be compressed or decompressed. Repeated calls to the library allow an unlimited number of blocks of data to be handled. Some ancillary code (counters) may suffer from overflow for long data streams, but this does not affect the actual compression or decompression.
When compressing a long (or infinite) data stream, it is advisable to write regular full-flush points.
Today, zlib is something of ade factostandard, to the point that zlib and DEFLATE are often used interchangeably in standards documents, with thousands of applications relying on it for compression, either directly or indirectly.[13] These include:
zlib is also used in many embedded devices, such as the AppleiPhone and SonyPlayStation 3, because the code is portable, liberally licensed, and has a relatively smallmemory footprint.
A commonly used library built on an old codebase, zlib is also frequentlyforked by third-parties that claim improvements to this library:
zlib was written by Jean-loup Gailly (compression) and Mark Adler (decompression).
Jean-Loup Gailly and Mark Adler designed the zlib format and ...
All multi-byte numbers in the format described here are stored with the MOST-significant byte first (at the lower memory address).
..., we number the bits of a byte so that bit 0 is the least-significant bit, ...
zlib-flate(1) – Debian General CommandsManual