Import
What it does
CompressionUtils provides static methods for LZ-based string compression and decompression. It supports multiple output formats — plain string, Base64, and Uint8Array — and includes convenience methods for compressing and decompressing JSON objects directly.
The compression algorithm is deterministic and synchronous. It works in both browser and Node.js environments without native dependencies.
Methods
compress(data, options?)
decompress(compressed)
compressToBase64(data)
decompressFromBase64(base64)
compressToUint8Array(data)
Uint8Array. Ideal for binary transport (WebSocket, IndexedDB).
decompressFromUint8Array(compressed)
Uint8Array back to the original string.
estimateCompressionRatio(data)
0.3 means the compressed output is roughly 30% of the original size.