dreamworkAPI
Ctrl K
GitHub
libraryDocs / lz4

lz4

librarysharedmenusource

LZ4 is lossless compression algorithm, providing compression speed > 500 MB/s per core (>0.15 Bytes/cycle).

Produces and consumes raw LZ4 blocks (no frame header, no checksum, no stored size) compatible with the reference LZ4_compress_fast / LZ4_decompress_safe.

Functions

lz4.compressCompresses a string into a raw LZ4 block.
lz4.decompressDecompresses a raw LZ4 block.

#lz4.compress

sharedmenunodiscardsource
function lz4.compress(data: string, acceleration?: integer): string

Compresses a string into a raw LZ4 block.

The block does not store the uncompressed size, keep it alongside the block if the receiving side needs to know it in advance.

Parameters
NameTypeDescription
datastringThe string to compress.
accelerationoptionalintegerA positive integer, defaults to 1. Higher values may increase the compression speed, especially on incompressible data, at the cost of compression efficiency.
Returns
TypeNameDescription
stringcompressedThe compressed data as a string.

#lz4.decompress

sharedmenunodiscardsource
function lz4.decompress(data: string): string

Decompresses a raw LZ4 block.

Throws an error on malformed input (truncated lengths/literals, offsets pointing before the start of the output, a block not ending with literals); call via pcall() when processing untrusted input.

LZ4 blocks carry no checksum, so corrupted data may still decode into wrong output, and a block cut exactly at a sequence boundary is indistinguishable from a shorter valid block.

Parameters
NameTypeDescription
datastringThe LZ4 block to decompress.
Returns
TypeNameDescription
stringdecompressedThe decompressed string.
Generated from the dreamwork meta branch.