lz4decompress Synchronous

  • crypt.lz4.decompress
  • crypt.lz4decompress
  • lz4.decompress

Expand an LZ4 block previously produced by lz4compress. Supply a capacity when the source is untrusted or your script has a known maximum document size.

Syntax
Luau
lz4decompress(data: string, maxOutputSize: number?) -> string

Parameters

Function parameters
ParameterTypeDescription
datastringCompressed LZ4 block.
maxOutputSizenumber?Optional nonnegative output capacity in bytes, up to 512 MiB. Omit it to use that default limit; explicit nil is rejected.

Returns

string

The original byte string. Invalid blocks and output that exceeds the selected capacity raise an error.

Usage notes

The optional second argument is a limit, not a promised output length. A valid result can be shorter.

Limits

ResourceLimitWhat happens
Compressed input512 MiBA larger string raises an error.
Decompressed output512 MiB, or maxOutputSize when it is smallerA larger result raises an error rather than being truncated. A maxOutputSize above 512 MiB also raises.

A small block can expand into a much larger string, so pass maxOutputSize and use pcall when the source is untrusted.

Differences from sUNC

Kawaii accepts an optional second argument, maxOutputSize. The sUNC signature lists only data. This argument is a capacity limit: decompressed output may be shorter than it.

Example

Example
Luau
local packed = lz4compress("saved preferences")
local ok, text = pcall(lz4decompress, packed, 1024)
if ok then print(text) end