Lz4.js is an implementation of Lz4 designed to be used in web browsers. It contains no dependencies on external libraries or Node.JS, though it is organized as a set of CommonJS modules. It is recommended to use Browserify or WebPack to bundle this for the web browser.
npm install lz4js
var lz4 = ;var fs = ;// Compress 128 bytes of zero.var compressed = lz4;// Decompress.var decompressed = lz4;// Compress file.bin to file.lz4.var data = fs;compressed = Buffer;fs;
Note: The high-level
decompressfunctions deal with framed Lz4 data and do not support raw block data nor legacy Lz4 blocks.
The API accepts either
Uint8Arrays. Arrays are expected to be arrays of unsigned 8-bit values. The API will return
Uint8Arrays if the browser supports them, or
compress(buffer: Array, maxSize: Number): Array
Compresses a buffer using Lz4. maxSize sets bounds on the output length; it is recommended to not specify this unless you know what you're doing. Any unused buffer data will be sliced before the buffer is returned.
decompress(buffer: Array, maxSize: Number): Array
Decompresses a buffer using Lz4. maxSize sets bounds on the output length; if you know the output length, this will reduce memory usage somewhat. Any unused buffer data will be sliced before the buffer is returned.