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.
Luau
zstdcompress(data: string, level: number?) -> stringParameters
| Parameter | Type | Description |
|---|---|---|
data | string | Text or binary bytes to compress. |
level | number? | Optional integer compression level from -131072 through 22; defaults to 1. |
Returns
stringA 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.
Example
Luau
local original = string.rep("session-state;", 100)
local packed = zstdcompress(original, 3)
assert(zstddecompress(packed) == original)
print(#packed, "compressed bytes")