Software:zlib

From HandWiki

zlib
zlib logo
Initial release1 May 1995 (1995-05-01)
Written inC
Operating systemCross-platform
TypeData compression
Licensezlib License
Websitezlib.net

zlib (/ˈzlɪb/ or "zeta-lib", /ˈztəˌlɪb/)[1][2] is a software library used for data compression as well as a data format.[3] 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.

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

Capabilities

Encapsulation

Raw DEFLATE compressed data (RFC 1951)[4] are typically written with a zlib or gzip wrapper encapsulating the data, by adding a header and footer. This provides stream identification and error detection that are not provided by the raw DEFLATE data.

The zlib wrapper (RFC 1950)[3] is smaller than the gzip wrapper (RFC 1952),[5] as the latter stores a file name and other file system information.

Algorithm

(As of September 2018), zlib only supports one algorithm, called DEFLATE, which uses a combination of a variation of LZ77 (Lempel–Ziv 1977) and Huffman coding.[6] 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 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.

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 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.[7] These include:

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

Forks

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

See also

References

  1. Stutz, Michael (October 22, 2004). The Linux Cookbook, 2nd Edition: Tips and Techniques for Everyday Use. No Starch Press. ISBN 9781593270315. https://books.google.com/books?id=hwJQOwg-MGYC&q=zeta. 
  2. Hall, John R. (October 22, 2001). Programming Linux Games. No Starch Press. ISBN 9781886411494. https://books.google.com/books?id=7eAPUdU3hRUC&q=zlib+zeelib&pg=PA68. 
  3. 3.0 3.1 RFC 1950, doi:10.17487/RFC1950, https://tools.ietf.org/html/rfc1950 
  4. RFC 1951, doi:10.17487/RFC1951, https://tools.ietf.org/html/rfc1951 
  5. RFC 1952, doi:10.17487/RFC1952, https://tools.ietf.org/html/rfc1952 
  6. rfc1951
  7. Gailly, Jean-loup; Adler, Mark (2002-04-18), zlib Applications, http://zlib.net/apps.html 
  8. "c++ - Why does cURL use zlib?". https://stackoverflow.com/questions/26244134/why-does-curl-use-zlib. 
  9. https://blog.cloudera.com/orcfile-in-hdp-2-better-compression-better-performance/ cite orc.compress=Zlib as default.
  10. System.IO.Compression.DeflateStream. MSDN Library.
  11. "MySQL :: MySQL 8.0 Reference Manual :: 15.9.1.5 How Compression Works for InnoDB Tables". https://dev.mysql.com/doc/refman/8.0/en/innodb-compression-internals.html. 
  12. "github Intel ZLIB" (in en). 25 January 2024. https://github.com/intel/zlib. 
  13. "Fighting Cancer: The Unexpected Benefit Of Open Sourcing Our Code" (in en). 8 July 2015. https://blog.cloudflare.com/cloudflare-fights-cancer/. 
  14. Rosbach, HK (24 February 2023). "zlib-ng/zlib-ng: zlib replacement with optimizations for "next generation" systems.". zlib-ng. https://github.com/zlib-ng/zlib-ng. 

External links