zstdcompress Synchronous

  • crypt.zstd.compress

Compress bytes with Zstandard, which is useful for saved data or transfers where compact output matters more than the quickest encode. Pass a level only when you need to tune the compression work.

Syntax
Luau
zstdcompress(data: string, level: number?) -> string

Parameters

Function parameters
ParameterTypeDescription
datastringText or binary bytes to compress.
levelnumber?Optional integer compression level from -131072 through 22; defaults to 1.

Returns

string

A Zstandard frame as a binary string.

Usage notes

A higher level can take more work and is not guaranteed to make a very small input smaller. Use zstddecompress for the resulting bytes.

Limits

ResourceLimitWhat happens
Input512 MiBA larger string raises an error.

Use pcall when the input size depends on external data.

Example

Example
Luau
local original = string.rep("session-state;", 100)
local packed = zstdcompress(original, 3)
assert(zstddecompress(packed) == original)
print(#packed, "compressed bytes")