Encoding
Encode and decode data with Base64, and compress or decompress with LZ4 — usable both standalone and through the crypt namespace.
Base64 and LZ4, available bare as well as through the crypt namespace. Base64 when binary has to survive as text; LZ4 when it has to be small.
Both directions
local raw = readfile("assets/blob.bin")
-- Small.
local packed = lz4compress(raw)
local restored = lz4decompress(packed, #raw) -- needs the original size
-- Text-safe.
local encoded = base64encode(raw)
local decoded = base64decode(encoded)Keep the original length
lz4decompress needs the uncompressed size. Store it alongside the payload — a two-key JSON wrapper is usually simplest.