cl-lzlib

2022-07-08

lzip (LZMA) (de)compression using bindings to lzlib

Upstream URL

github.com/glv2/cl-lzlib

Author

Guillaume LE VAILLANT

License

GPL-3
README
cl-lzlib

1Description

cl-lzlib is a Common Lisp library for lzip (LZMA) compression/decompression using bindings to the lzlib C library.

2License

cl-lzlib is released under the GPL-3 license or later. See the LICENSE file for details.

3Dependencies

cl-lzlib requires:

cl-lzlib can be easily installed with quicklisp.

A lzlib package should be available in almost every GNU/Linux or *BSD distribution. For example it is called lzlib on Gentoo and Guix, and liblz1 on Debian and Ubuntu.

4API

The library can be loaded with the usual:

(asdf:load-system "lzlib")

or

(quicklisp:quickload "lzlib")

The functions will then be available in the lzlib package.

4.1Compression

The compression can be customized using serveral parameters:

  • The maximum size of members inside the lzip archive can be indicated with themember-size parameter. The default value is 2 PiB.
  • The compression level can be indicated either using the level parameter, orby using both the dictionary-size and match-len-limit parameters. Thedefault level is 6, which sets dictionary-size to 8 MiB andmatch-len-limit to 36. level must be between 0 (fast encoder) and9 (strong compression).
  • When the threads parameter is greater than 1, the data is read by blocksof block-size bytes and the blocks are compressed in parallel. The defaultblock size is the double of the dictionary size.
(compress-stream input output &key threads level member-size block-size dictionary-size match-len-limit) => t

Read the data from the input octet stream, compress it, and write the result to the output octet stream.

(compress-file input output &key threads level member-size block-size dictionary-size match-len-limit) => t

Read the data from the input file, compress it, and write the result to the output file.

(compress-buffer buffer &key start end threads level member-size block-size dictionary-size match-len-limit) => bytes

Read the data between the start and end offsets in the buffer, compress it, and return the resulting octet vector.

(make-compressing-stream output-stream &key level member-size dictionary-size match-len-limit) => stream

Return a stream that will compress the bytes written to it at the given compression level and write them to the output-stream.

(with-compressing-stream (stream output-stream &key level member-size dictionary-size match-len-limit) &body body)

Within body, stream is bound to a compressing stream for the given compression level and output-stream. The result of the last form of body is returned.

4.2Decompression

The decompression can be customized using serveral parameters:

  • When an archive has some trailing data, if ignore-trailing is nil anerror will be generated, otherwise the trailing data will be ignored.
  • When an archive has some trailing data looking like a corrupt header, ifloose-trailing is nil an error will be generated, otherwise the trailingdata will be ignored.
  • When the threads parameter is greater than 1, the library will decompressthe members of the archive in parallel. Note that if the archive only has1 member, the decompression will be faster and use less memory whenthreads is also 1.
(decompress-stream input output &key threads ignore-trailing loose-trailing) => t

Read the data from the input octet stream, decompress it, and write the result to the output octet stream.

(decompress-file input output &key threads ignore-trailing loose-trailing) => t

Read the data from the input file, decompress it, and write the result to the output file.

(decompress-buffer buffer &key start end threads ignore-trailing loose-trailing) => bytes

Read the data between the start and end offsets in the buffer, decompress it, and return the resulting octet vector.

(make-decompressing-stream input-stream &key ignore-trailing loose-trailing) => stream

Return a stream that will supply the bytes resulting from the decompression of the data read from the input-stream.

(with-decompressing-stream (stream input-stream &key ignore-trailing loose-trailing) &body body)

Within body, stream is bound to a decompressing stream for the given input-stream. The result of the last form of body is returned.

5Tests

The tests require the fiveam package. They can be run with:

(asdf:test-system "lzlib")

Dependencies (6)

  • cffi
  • cl-octet-streams
  • fiveam
  • lparallel
  • trivial-gray-streams
  • uiop

Dependents (0)

    • GitHub
    • Quicklisp