Module crypto.comp

Low-level Lua interface to the Linux Kernel Crypto API for synchronous compression algorithms.

This module provides a new function to create COMP transform objects, which can then be used for compression and decompression.

Class COMP

comp:compress (data, max_output_len) Compresses the given data.
comp:decompress (data, max_output_len) Decompresses the given data.

comp

new (algname) Creates a new COMP transform (TFM) object.


Class COMP

COMP Object methods. These methods are available on COMP objects created by comp.new().
comp:compress (data, max_output_len)
Compresses the given data. Requires the maximum possible compressed size as an argument, as the kernel API needs a destination buffer of sufficient size. A common approach is to provide a size slightly larger than the input data (e.g., input size + a small fixed overhead or percentage).

Parameters:

  • data string The data to compress.
  • max_output_len integer The maximum possible size of the compressed data.

Returns:

    string The compressed data.

Raises:

Error on failure (e.g., allocation error, crypto API error).
comp:decompress (data, max_output_len)
Decompresses the given data. Requires the maximum possible decompressed size as an argument, as the kernel API needs a destination buffer of sufficient size.

Parameters:

  • data string The data to decompress.
  • max_output_len integer The maximum possible size of the decompressed data.

Returns:

    string The decompressed data.

Raises:

Error on failure (e.g., allocation error, crypto API error, input data corrupted,

    <code>max\_output\_len</code> too small).

comp

new (algname)
Creates a new COMP transform (TFM) object. This is the constructor function for the crypto_comp module.

Parameters:

  • algname string The name of the compression algorithm (e.g., "lz4", "deflate").

Returns:

    comp The new COMP TFM object.

Raises:

Error if the TFM object cannot be allocated/initialized.

Usage:

    local comp = require("crypto.comp")
    local compressor = comp.new("lz4")
generated by LDoc 1.5.0 Last updated 2025-08-04 15:54:20