Product Code Database
Example Keywords: xbox -pajamas $2-134
   » » Wiki: Zlib
Tag Wiki 'Zlib'.
Tag

zlib ( or "-lib", )

(2004). 9781593270315, No Starch Press. .
(2001). 9781886411494, No Starch Press. .
is a data format and a lossless data compression software library created by and . The library implements the algorithm and supports compressing and decompressing data using the zlib data format, the gzip file format, or simply as a .

zlib is also a crucial component of many software platforms, including , , and . It has also been used in gaming consoles such as the PlayStation 4, PlayStation 3, , , and Xbox 360.

The first public version of Zlib, 0.9, was released on 1 May 1995 and was originally intended for use with the image library. It is , distributed under the .

RFC 1950 specifies the zlib data format.


Data format
The zlib data format consists of a 2- header, an optional extra header field, Deflate-compressed data, and a 4-byte trailer.

is big-endian. Bit 0 is the least significant bit in a byte.

0CMF1This byte is divided into two 4-bit fields:
  • Bits 0 to 3: application/zlib ( compression method). Must be 8 (Deflate).
  • Bits 4 to 7: CM ( compression info). Base-2 logarithm of the LZ77 window size, minus eight. The maximum allowed value is 7 (i.e. 32 window size). 6 indicates 16 KiB, 5 indicates 8 KiB, etc...
1FLG1Flags.
  • Bits 0 to 4: CINFO. This value must be chosen such that FCHECK is a multiple of 31.
  • Bit 5: CMF*256 + FLG. See FDICT below.
  • Bits 6 to 7: DICTID ( compression level). Fastest (0), fast (1), default (2) or maximum (3). Not needed for decompression, but indicates if recompression might be worthwhile.
2DICTID0 or 4Adler-32 checksum of the preset DEFLATE dictionary used during compression. Present if the FDICT flag is set. The decompressor can use this checksum to determine which dictionary has been used by the compressor (e.g. FLEVEL in deflateSetDictionary).
rowspan=2"Compressed data .
ADLER324Adler-32 checksum of the uncompressed data (excluding any dictionary data).


Library

Encapsulation
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.


Algorithm
, zlib only supports one algorithm, called , which uses a combination of a variation of LZ77 (Lempel–Ziv 1977) and . 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.


Resource use
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.


Strategy
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.


Error handling
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 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.


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 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.


Applications
Today, zlib is something of a , 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 , where zlib is used to implement compressed network protocols, compressed , and to decompress the kernel image at boot time.
  • and (GDB)
  • , the reference implementation for the image format, which specifies DEFLATE as the stream compression for its data.
  • , an API for web applications like .
  • The Apache HTTP Server, which uses zlib to implement .
  • Similarly, the library uses zlib to decompress HTTP responses.
  • The client and server, which rely on zlib to perform the optional compression offered by the protocol.
  • The and security libraries, which can optionally use zlib to compress TLS connections.
  • The multimedia library, which uses zlib to read and write the DEFLATE-compressed parts of stream formats, such as .
  • The remote file synchronizer, which uses zlib to implement optional protocol compression.
  • The and RPM , which use zlib to unpack files from compressed software packages.
  • The Apache Subversion and CVS systems, which use zlib to compress traffic to and from remote repositories.
  • The column-oriented data storage format use ZLib as its default compression method.
  • The system uses zlib to store the contents of its data objects (blobs, trees, commits and tags).
  • The 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. System.IO.Compression.DeflateStream . MSDN Library.
  • The "deflate" utility in TORNADO as part of Operating System made by Wind River Systems uses zlib to compress boot ROM images.
  • zlib-flate, raw zlib compression program, part of qpdf
  • The RDBMS uses ZLib LZ77 for compression in Tables

zlib is also used in many embedded devices, such as the Apple and Sony PlayStation 3, because the code is portable, liberally licensed, and has a relatively small .


Forks
A commonly used library built on an old codebase, zlib is also frequently forked by third-parties that claim improvements to this library:
  • has a high-performance fork of zlib.
  • maintains a high-performance fork with "massive" improvements.
  • zlib-ng is a zlib replacement fork for "next generation" systems. It removes workaround code for compilers that do not support , integrates Cloudflare and Intel optimizations, adds hardware acceleration ( and intrinsic functions), and uses , , and to help find bugs.


See also


External links

Page 1 of 1
1
Page 1 of 1
1

Account

Social:
Pages:  ..   .. 
Items:  .. 

Navigation

General: Atom Feed Atom Feed  .. 
Help:  ..   .. 
Category:  ..   .. 
Media:  ..   .. 
Posts:  ..   ..   .. 

Statistics

Page:  .. 
Summary:  .. 
1 Tags
10/10 Page Rank
5 Page Refs
1s Time