This article needs additional citations for verification. (March 2021)
|Initial release||1 May 1995|
1.2.11 / 15 January 2017
zlib (// or "zeta-lib", //) is a software library used for data compression. zlib was written by Jean-loup Gailly and Mark Adler and is an abstraction of the DEFLATE compression algorithm used in their gzip file compression program. zlib is also a crucial component of many software platforms, including Linux, macOS, and iOS. It has also been used in gaming consoles such as the PlayStation 4, PlayStation 3, Wii U, Wii, Xbox One and Xbox 360.
zlib compressed data are typically written with a gzip or a zlib wrapper. The wrapper encapsulates the raw DEFLATE data by adding a header and trailer. This provides stream identification and error detection that are not provided by the raw DEFLATE data.
The gzip header, used in the ubiquitous gzip file format, is larger than the zlib header, as it stores a file name and other file system information.
As of September 2018[update], zlib only supports one algorithm, called DEFLATE, which uses a combination of a variation of LZ77 (Lempel–Ziv 1977) and Huffman coding. This algorithm provides good compression on a wide variety of data with minimal use of system resources. This is also the algorithm used in the Zip 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, the run-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 some data 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 a de facto standard, 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. These include:
- The Linux kernel, where zlib is used to implement compressed network protocols, compressed file systems, and to decompress the kernel image at boot time.
- GNU Binutils and GNU Debugger (GDB)
- libpng, the reference implementation for the PNG image format, which specifies DEFLATE as the stream compression for its bitmap data.
- libwww, an API for Web applications like Web browsers.
- The Apache HTTP Server, which uses zlib to implement HTTP/1.1.
- Similarly, the cURL library uses zlib to decompress HTTP responses.
- The OpenSSH client and server, which rely on zlib to perform the optional compression offered by the Secure Shell protocol.
- The OpenSSL and GnuTLS security libraries, which can optionally use zlib to compress TLS connections.
- The FFmpeg multimedia library, which uses zlib to read and write the DEFLATE-compressed parts of stream formats, such as Matroska.
- The rsync remote file synchronizer, which uses zlib to implement optional protocol compression.
- The dpkg and RPM package managers, which use zlib to unpack files from compressed software packages.
- The Apache Subversion and CVS version control systems, which use zlib to compress traffic to and from remote repositories.
- The Apache ORC column-oriented data storage format use ZLib as its default compression method.
- The Git version control system uses zlib to store the contents of its data objects (blobs, trees, commits and tags).
- The PostgreSQL RDBMS uses zlib with custom dump format (pg_dump -Fc) for database backups.
- The class System.IO.Compression.DeflateStream of the Microsoft .NET Framework 2.0 and higher.
- The "deflate" utility in TORNADO as part of VxWorks Operating System made by Wind River Systems uses zlib to compress boot ROM images.
- qpdf , raw zlib compression program, part of
- The MySQL RDBMS uses ZLib LZ77 for compression in InnoDB Tables 
A commonly used library built on an old codebase, zlib is also frequently forked by third-parties that claim improvements to this library:
- Intel has a high-performance fork of zlib.
- CloudFlare maintains a high-performance fork with "massive" improvements.
- Zlib-ng is a zlib replacement fork with optimizations for "next generation" systems.
- Stutz, Michael (October 22, 2004). The Linux Cookbook, 2nd Edition: Tips and Techniques for Everyday Use. No Starch Press. ISBN 9781593270315 – via Google Books.
- Inc, Loki Software; Hall, John R. (October 22, 2001). Programming Linux Games. No Starch Press. ISBN 9781886411494 – via Google Books.
- Gailly, Jean-loup; Adler, Mark (2002-04-18), zlib Applications
- "c++ - Why does cURL use zlib?". Stack Overflow.
- https://blog.cloudera.com/orcfile-in-hdp-2-better-compression-better-performance/ cite
- System.IO.Compression.DeflateStream. MSDN Library.
- "MySQL :: MySQL 8.0 Reference Manual :: 126.96.36.199 How Compression Works for InnoDB Tables". dev.mysql.com.
- "Intel® IPP ZLIB Coding Functions". Intel Software. 31 July 2019. Retrieved 18 January 2020.
- "Fighting Cancer: The Unexpected Benefit Of Open Sourcing Our Code". The Cloudflare Blog. 8 July 2015.