Zlib

This MedLibrary.org supplementary page on Zlib is provided directly from the open source Wikipedia as a service to our readers. Please see the note below on authorship of this content, as well as the Wikipedia usage guidelines. To search for other content from our encyclopedia supplement, please use the form below:


zlib
zlib logo
Latest release 1.2.3 / 2005-07-18
Written in C
OS cross platform
Type data compression
License zlib license
Website zlib.net

zlib 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. The first public version, 0.9, was released on 1 May 1995 and was originally intended for use with libpng image library. It is free software, distributed under the zlib license.

As of March 2007, zlib is included in Coverity’s Department of Homeland Security-sponsored ongoing examination of select open-source projects.1

Contents

Capabilities

  • Header - zlib can compress data using a gzip header, a zlib header, or no header

Typically data is compressed using the zlib header as this provides error detection etc. When data is written without a header the result is raw DEFLATE data with no error detection and it is up to the caller of the decompression software to know where the compressed data ends.

The gzip header is larger than the zlib header as it stores a file name and other file system information - in fact this is the header format used in the ubiquitous gzip file format. Note that the zlib library cannot itself create a gzip file, but it is fairly trivial to do this by writing the compressed data to a file with a gzip header.

  • Algorithm - currently zlib only supports one algorithm called DEFLATE which is a variation of LZ77 (Lempel-Ziv 1977)

This algorithm provides good compression on a wide variety of data with minimal use of system resources. This is also the algorithm almost invariably use nowadays in ZIP (file format) (though the zip file format supports several other algorithms also).

It is unlikely that the zlib format will ever be extended to use any other algorithms, though the header makes allowance for this possibility.

  • Resource use - the library provides facilities for control of processor and memory use

A compression level value may be supplied which trades-off speed with compression.

There are also facilities for conserving memory. These are probably only useful in restricted memory environments such as some embedded systems.

  • Strategy - the compression can be optimized for specific types of data

If you are using the library to always compress specific types of data then using a specific strategy may improve compression and performance. For example, if your data contains long lengths of repeated bytes then the RLE (run-length encoding) strategy may give better results.

For general data, the default strategy is preferred.

  • Error handling - errors can be detected and skipped

Data corruption can be detected (as long as the data is written with a zlib or gzip header - see above).

Further, if full-flush points are written to the compressed stream then corrupt data can be skipped and the decompression will resynchronise at the next flush point. (No error recovery of the corrupt data is provided.) Full-flush points are useful for large data streams on unreliable channels where some last data loss is unimportant (eg multimedia), however creating too many flush points can dramatically affect speed and compression.

  • Data length - there is no limit to the length of data that can be compressed or decompressed

Repeated calls to the library allow an unlimited numbers of blocks of data to be handled. Some ancillary code (counters) may suffer from overflow for long data streams but this does not affect tha actual compression or decompression.

When compressing a long (or infinite) data stream it would be advisable to write regular full-flush points.

Applications

Today, zlib is something of a de facto standard, to the point that zlib and DEFLATE are often used interchangeably in standards documents. Thousands of applications rely on it for compression, directly or indirectly,2 including:

  • The Linux kernel, where it is used to implement compressed network protocols, compressed file systems and to decompress the kernel image itself at boot time.
  • libpng, the reference implementation for the PNG image format, which specifies DEFLATE as the stream compression for its bitmap data.
  • The Apache HTTP server, which uses zlib to implement HTTP/1.1.
  • 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 Subversion and CVS version control systems, which use zlib to compress traffic to and from remote repositories.
  • The Git version control system uses zlib to store the contents of it's data objects (blobs, trees, commits and tags).

zlib is also used in many embedded devices because the code is portable, liberally-licensed and has a relatively small memory footprint.

See also

References

External links

Wikipedia content modification information:

  • This page was last modified on 4 December 2008, at 11:57.

Wikipedia Authorship and Review

Wikipedia content provided here is not reviewed directly by MedLibrary.org. Wikipedia content is authored by an open community of volunteers and is not produced by or in any way affiliated with MedLibrary.org.

Wikipedia Usage Guidelines

This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article on "Zlib".

The URL for this specific entry is:

All Wikipedia text is available under the terms of the GNU Free Documentation License. (See Copyrights for details). Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.