6 Module LZ4
gullradriel edited this page 2026-10-29 20:54:40 +01:00

LZ4: shortcuts to easy compress/decompress data

Functions

Name
N_STR * zip4_nstr(N_STR * src)
Return a compressed version of src using LZ4 block format.
N_STR * unzip4_nstr(N_STR * src)
Return an uncompressed version of src produced by zip4_nstr.

Functions Documentation

function zip4_nstr

N_STR * zip4_nstr(
    N_STR * src
)

Return a compressed version of src using LZ4 block format.

Compress src with LZ4 block format.

Self-framing, the output starts with a u32 (network byte order) carrying the original uncompressed length, followed by the lz4-compressed payload. Returns NULL on error.

Return a compressed version of src using LZ4 block format.

Self-framing, the produced N_STR begins with a u32 (network byte order) holding the original uncompressed length, followed by the LZ4-compressed bytes. Matches zip_nstr's framing so unzip{4,}_nstr can be selected per inbound packet without a separate framing header.

function unzip4_nstr

N_STR * unzip4_nstr(
    N_STR * src
)

Return an uncompressed version of src produced by zip4_nstr.

Decompress an N_STR produced by zip4_nstr.

Rejects payloads whose decoded-size header is absurdly large to stop a malicious sender from over-allocating. Returns NULL on error.

Return an uncompressed version of src produced by zip4_nstr.

Rejects inputs whose declared original size exceeds 256 MiB as a defence against malicious / corrupt frames causing a large allocation. Matches the same cap unzip_nstr uses.