lz4decompress Synchronous
crypt.lz4.decompresscrypt.lz4decompresslz4.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.
Luau
lz4decompress(data: string, maxOutputSize: number?) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | Compressed LZ4 block. |
maxOutputSize | number? | Optional nonnegative output capacity in bytes, up to 512 MiB. Omit it to use that default limit; explicit nil is rejected. |
Returns
stringThe 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
| Resource | Limit | What happens |
|---|---|---|
| Compressed input | 512 MiB | A larger string raises an error. |
| Decompressed output | 512 MiB, or maxOutputSize when it is smaller | A 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
Luau
local packed = lz4compress("saved preferences")
local ok, text = pcall(lz4decompress, packed, 1024)
if ok then print(text) end