lz4
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.compress | Compresses a string into a raw LZ4 block. |
lz4.decompress | Decompresses a raw LZ4 block. |
#lz4.compress
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.
| Name | Type | Description |
|---|---|---|
data | string | The string to compress. |
accelerationoptional | integer | A positive integer, defaults to 1. Higher values may increase the compression speed, especially on incompressible data, at the cost of compression efficiency. |
| Type | Name | Description |
|---|---|---|
string | compressed | The compressed data as a string. |
#lz4.decompress
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.
| Name | Type | Description |
|---|---|---|
data | string | The LZ4 block to decompress. |
| Type | Name | Description |
|---|---|---|
string | decompressed | The decompressed string. |