Software:LZ4 (compression algorithm)

From HandWiki
Short description: Compression algorithm
LZ4
Original author(s)Yann Collet
Developer(s)Yann Collet
Initial release24 April 2011 (2011-04-24)
Stable release
1.9.4 / 16 August 2022; 18 months ago (2022-08-16)[1]
Written inC
Operating systemCross-platform
PlatformPortable
TypeData compression
LicenseSimplified BSD License
Website{{{1}}}
LZ4 Frame Format
Magic number04 22 4d 18[2]
Type of formatData compression
Websitehttps://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md

LZ4 is a lossless data compression algorithm that is focused on compression and decompression speed. It belongs to the LZ77 family of byte-oriented compression schemes.

Features

The LZ4 algorithms aims to provide a good trade-off between speed and compression ratio. Typically, it has a smaller (i.e., worse) compression ratio than the similar LZO algorithm, which in turn is worse than algorithms like DEFLATE. However, LZ4 compression speed is similar to LZO and several times faster than DEFLATE, while decompression speed is significantly faster than LZO.[3]

Design

LZ4 only uses a dictionary-matching stage (LZ77), and unlike other common compression algorithms does not combine it with an entropy coding stage (e.g. Huffman coding in DEFLATE).[4][5]

The LZ4 algorithm represents the data as a series of sequences. Each sequence begins with a one-byte token that is broken into two 4-bit fields. The first field represents the number of literal bytes that are to be copied to the output. The second field represents the number of bytes to copy from the already decoded output buffer (with 0 representing the minimum match length of 4 bytes). A value of 15 in either of the bitfields indicates that the length is larger and there is an extra byte of data that is to be added to the length. A value of 255 in these extra bytes indicates that yet another byte is to be added. Hence arbitrary lengths are represented by a series of extra bytes containing the value 255. The string of literals comes after the token and any extra bytes needed to indicate string length. This is followed by an offset that indicates how far back in the output buffer to begin copying. The extra bytes (if any) of the match-length come at the end of the sequence.[6][7]

Compression can be carried out in a stream or in blocks. Higher compression ratios can be achieved by investing more effort in finding the best matches. This results in both a smaller output and faster decompression.

Implementation

The reference implementation in C by Yann Collet is licensed under a BSD license. There are ports and bindings in various languages including Java, C#, Rust, and Python.[8] The Apache Hadoop system uses this algorithm for fast compression. LZ4 was also implemented natively in the Linux kernel 3.11.[9] The FreeBSD, Illumos, ZFS on Linux, and ZFS-OSX implementations of the ZFS filesystem support the LZ4 algorithm for on-the-fly compression.[10][11][12][13] Linux supports LZ4 for SquashFS since 3.19-rc1.[14] LZ4 is also supported in newer zstd command line utility by Yann Collet.

  • LZ4 available in extended 7zip-Version.[15]

References

  1. "LZ4 latest release". https://github.com/lz4/lz4/releases/latest. 
  2. Collet, Yann. "LZ4 Frame Format Description". https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md. 
  3. Michael Larabel (2013-01-28). "Support For Compressing The Linux Kernel With LZ4". Phoronix. https://www.phoronix.com/scan.php?page=news_item&px=MTI4NjM. 
  4. Collet, Yann (2019-03-30). "LZ4 Block Format Description". https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md. "There is no entropy encoder back-end nor framing layer." 
  5. DEFLATE Compressed Data Format Specification version 1.3, IETF, doi:10.17487/RFC1951, RFC 1951, https://tools.ietf.org/html/rfc1951, retrieved 2020-07-09 
  6. Yann Collet (2011-05-26). "RealTime Data Compression". http://fastcompression.blogspot.com/2011/05/lz4-explained.html. 
  7. ticki (2016-10-25). "How LZ4 works". https://ticki.github.io/blog/how-lz4-works/. 
  8. on GitHub
  9. Jonathan Corbet (2013-07-19). "Kernel development". LWN.net. https://lwn.net/Articles/557814/. 
  10. "FreeBSD 9.2-RELEASE Release Notes". FreeBSD. 2013-11-13. https://www.freebsd.org/releases/9.2R/relnotes.html. 
  11. "LZ4 Compression". illumos. http://wiki.illumos.org/display/illumos/LZ4+Compression. 
  12. on GitHub
  13. "Features: lz4 compression". OpenZFS. http://www.open-zfs.org/wiki/Features#lz4_compression. 
  14. Phillip Lougher (2014-11-27). "Squashfs: Add LZ4 compression configuration option". https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=62421645bb702c077ee5a462815525106cb53bcf. 
  15. 7-zip-zstd

External links