https://github.com/benzinga/lz4js
Lz4 for the browser.
https://github.com/benzinga/lz4js
javascript lz4 travis-ci
Last synced: 6 months ago
JSON representation
Lz4 for the browser.
- Host: GitHub
- URL: https://github.com/benzinga/lz4js
- Owner: Benzinga
- Created: 2016-07-05T19:37:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-16T13:55:22.000Z (over 2 years ago)
- Last Synced: 2025-03-10T03:30:41.700Z (7 months ago)
- Topics: javascript, lz4, travis-ci
- Language: JavaScript
- Size: 30.3 KB
- Stars: 93
- Watchers: 9
- Forks: 23
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lz4.js [](https://www.npmjs.com/package/lz4js) [](https://travis-ci.org/Benzinga/lz4js) [](https://codecov.io/gh/Benzinga/lz4js)
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.## Installation
```
npm install lz4js
```## Usage
```javascript
var lz4 = require("lz4js");
var fs = require("fs");// Compress 128 bytes of zero.
var compressed = lz4.compress(new Array(128));// Decompress.
var decompressed = lz4.decompress(compressed);// Compress file.bin to file.lz4.
var data = fs.readFileSync("file.bin");
compressed = Buffer.from(lz4.compress(data));
fs.writeFileSync('file.lz4', compressed);
```> **Note**: The high-level `compress` and `decompress` functions deal with framed Lz4 data and do not support raw block data nor legacy Lz4 blocks.
## API
The API accepts either `Array`s or `Uint8Array`s. Arrays are expected to be arrays of unsigned 8-bit values. The API will return `Uint8Array`s if the browser supports them, or `Array`s otherwise.- `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.