lz4decompress
Decompresses LZ4-compressed data.
function lz4decompress(data: string, size: number): stringSynopsis
How it works
Decompresses LZ4LZ4A high-speed lossless compression algorithm. Prioritizes speed over ratio (~4 GB/s decompression). Uses a hash table to find duplicate byte sequences and encodes them as offset+length back-references.-compressed data back to the original string. The compressed format consists of literal/match token pairspairs()Returns an iterator that traverses all key-value pairs in a table (both array and hash parts). Order is not guaranteed for non-integer keys. Uses the next() function internally.. Decompression is a simple sequential process:
For each token:
1. Read literal length (4 high bits) → copy N raw bytes to output
2. Read match offset (16-bit LE) + match length (4 low bits)
3. Copy matchLength bytes from output[pos - offset] to output[pos]
LZ4 decompression runs at ~4 GB/s because it's purely memcpymemcpyA C standard library function that copies N bytes from a source memory address to a destination. Fundamental to LZ4 decompression and many VM operations. Very fast on modern CPUs due to SIMD optimization. operations with no entropy decoding. The rawSize parameter specifies the expected decompressed size for buffer pre-allocation.Usage
Decompress
local text = "Hello, world! Hello, world!"
local comp = lz4compress(text)
print(lz4decompress(comp, #text))Parameters
data string The LZ4-compressed bytes.
size number The expected size of the decompressed output.
Returns
string The decompressed string.