Cryptography

lz4decompress

Decompresses raw LZ4 block bytes with LZ4 block decompression and returns raw decompressed bytes as a Lua string.

Syntax

lz4decompress(data: string, originalSize?: number): string
Aliases crypt.lz4decompresscrypt.lz4.decompresslz4.decompress

Arguments

NameTypeDescription
datastringRaw compressed bytes passed to LZ4 block decompression.
originalSize?numberOutput buffer size passed as dstCapacity. For lz4compress output, pass the original uncompressed byte length; when omitted, the compressed input length is used.

Returns

NameTypeDescription
decompressedstringRaw decompressed bytes returned as a Lua string. The output can be shorter than originalSize.

Description

Decompresses raw LZ4 block bytes with LZ4 block decompression and returns raw decompressed bytes as a Lua string.

Call it with 2 parameter(s): data, originalSize. The argument table explains which values are required and which ones only refine the behavior.

It returns decompressed (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Decompress LZ4 bytes by passing the original uncompressed size.

local source = "Real Docs"
local compressed = lz4compress(source)
local decompressed = lz4decompress(compressed, #source)

print(decompressed)
print(decompressed == source)