Skip to main content
Decompresses compressed and returns exactly expectedSize bytes.
Input must be LZ4 Block format - see the page entry crypt.lz4compress to learn more.
expectedSize is the length of the original plaintext in bytes, not the length of the compressed input - you have to track and pass it yourself.
There is no integrity check - if the bytes are damaged or expectedSize is wrong,
the function still returns a string of that length without raising an error.

Parameters

Returns

string - the decompressed bytes, padded or truncated to exactly expectedSize characters.
When expectedSize matches the original length, the result is the full plaintext.

Aliases

  • lz4decompress

Example

In a chat-event-based Roblox game, stream Bad Apple as ASCII video over a remote at 30fps.
Reason: storing >1800 frames and parsing them would be a lot more easier if you compress the data beforehand.
There is no built-in integrity check. If the compressed string is malformed, or expectedSize is wrong, you get back a string that looks valid, but actually isn’t. For any data, store a hash alongside the payload (crypt.hash works) and verify after decompressing.