Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

zlib

From Wikipedia, the free encyclopedia
icon
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)
Data format and compression library
Not to be confused withZ-Library.
zlib (library)
zlib logo
Developers[1]
Initial release1 May 1995 (1995-05-01)
Stable release
1.3.2[2] / 17 February 2026; 2 days ago (17 February 2026)
Written inC
Operating systemCross-platform
TypeData compression
Licensezlib License
Websitezlib.net Edit this on Wikidata
Repository

zlib (/ˈzlɪb/ or "zeta-lib",/ˈztəˌ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]

Data format

[edit]
zlib (data format)
Internet media type
application/zlib[7]
Size limitationUnlimited
Developed by[8]
Type of formatData compression
CompressionLossless
Container forDeflate stream
StandardRFC 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
0CMF1

This byte is divided into two 4-bit fields:

  • Bits 0 to 3:CM (compression method). Must be 8 (Deflate).
  • Bits 4 to 7:CINFO (compression info). Base-2 logarithm of theLZ77 window size, minus eight. The maximum allowed value is 7 (i.e. 32KiB window size). 6 indicates 16 KiB, 5 indicates 8 KiB, etc...
1FLG1

Flags.

  • Bits 0 to 4:FCHECK. This value must be chosen such thatCMF*256 + FLG is amultiple of 31.
  • Bit 5:FDICT. SeeDICTID below.
  • Bits 6 to 7:FLEVEL (compression level). Fastest (0), fast (1), default (2) or maximum (3). FLEVEL is not needed for decompression. It indicates if recompression might be worthwhile.
2DICTID0 or 4Adler-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).
VariesCompressed dataVariesDeflate stream.
ADLER324Adler-32 checksum of theuncompressed data (excluding any dictionary data).

Library

[edit]

Encapsulation

[edit]

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

[edit]

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.

Resource use

[edit]

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

[edit]

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.

Error handling

[edit]

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.

Data length

[edit]

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

[edit]

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.

Forks

[edit]

A commonly used library built on an old codebase, zlib is also frequentlyforked by third-parties that claim improvements to this library:

See also

[edit]

References

[edit]
  1. ^"zlib Home Site".zlib.net. Archived fromthe original on 2 June 2006.zlib was written by Jean-loup Gailly (compression) and Mark Adler (decompression).
  2. ^"zlib 1.3.2 Release Notes". Archived fromthe original on 17 February 2026.
  3. ^Stutz, Michael (October 22, 2004).The Linux Cookbook, 2nd Edition: Tips and Techniques for Everyday Use. No Starch Press.ISBN 9781593270315.Archived from the original on January 25, 2023. RetrievedOctober 28, 2021 – via Google Books.
  4. ^Loki Software; Hall, John R. (October 22, 2001).Programming Linux Games. No Starch Press.ISBN 9781886411494.Archived from the original on July 11, 2024. RetrievedOctober 28, 2021 – via Google Books.
  5. ^"zlib 1.3.1 Manual".zlib.net. Archived fromthe original on 8 February 2024.
  6. ^RFC 1950.doi:10.17487/RFC1950.
  7. ^RFC 6713.doi:10.17487/RFC6713.
  8. ^Acknowledgements. p. 8.doi:10.17487/RFC1950.RFC1950.Jean-Loup Gailly and Mark Adler designed the zlib format and ...
  9. ^Overall conventions. p. 4.doi:10.17487/RFC1950.RFC1950.All multi-byte numbers in the format described here are stored with the MOST-significant byte first (at the lower memory address).
  10. ^Overall conventions. p. 4.doi:10.17487/RFC1950.RFC1950...., we number the bits of a byte so that bit 0 is the least-significant bit, ...
  11. ^Data format. p. 4.doi:10.17487/RFC1950.RFC1950.
  12. ^RFC 1951.doi:10.17487/RFC1951.
  13. ^Gailly, Jean-loup; Adler, Mark (2002-04-18),zlib Applications,archived from the original on 2019-06-10, retrieved2007-12-09
  14. ^"c++ - Why does cURL use zlib?".Stack Overflow.
  15. ^"ORCFile in HDP 2: Better Compression, Better Performance". 6 September 2013.Archived from the original on 6 August 2020. Retrieved16 May 2020.
  16. ^System.IO.Compression.DeflateStreamArchived 2016-02-06 at theWayback Machine. MSDN Library.
  17. ^zlib-flate(1) – Debian General CommandsManual
  18. ^"qpdf".Archived from the original on 2024-07-11. Retrieved2021-03-28.
  19. ^"MySQL :: MySQL 8.0 Reference Manual :: 15.9.1.5 How Compression Works for InnoDB Tables".dev.mysql.com.Archived from the original on 2021-08-01. Retrieved2021-07-14.
  20. ^"github Intel ZLIB".github. 25 January 2024.Archived from the original on 25 January 2024. Retrieved25 January 2024.
  21. ^"Fighting Cancer: The Unexpected Benefit Of Open Sourcing Our Code".The Cloudflare Blog. 8 July 2015.Archived from the original on 21 September 2019. Retrieved18 January 2020.
  22. ^Rosbach, HK (24 February 2023)."zlib-ng/zlib-ng: zlib replacement with optimizations for "next generation" systems".GitHub. zlib-ng.Archived from the original on 20 April 2020. Retrieved18 January 2020.

External links

[edit]
Retrieved from "https://en.wikipedia.org/w/index.php?title=Zlib&oldid=1339233474"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp