Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antoniomuso/lz4-napi
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.
https://github.com/antoniomuso/lz4-napi
bindings compression compression-library fast javascript lz4 napi napi-rs node-api nodejs rust rust-lang
Last synced: 13 days ago
JSON representation
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.
- Host: GitHub
- URL: https://github.com/antoniomuso/lz4-napi
- Owner: antoniomuso
- License: mit
- Created: 2021-11-25T17:51:34.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-24T07:51:26.000Z (19 days ago)
- Last Synced: 2024-10-26T03:09:21.428Z (17 days ago)
- Topics: bindings, compression, compression-library, fast, javascript, lz4, napi, napi-rs, node-api, nodejs, rust, rust-lang
- Language: JavaScript
- Homepage:
- Size: 3.07 MB
- Stars: 52
- Watchers: 2
- Forks: 2
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# lz4-napi
> Node.js NAPI Binding for LZ4 compression algorithm, powered by Rust [napi-rs](https://napi.rs) and [lz4-flex](https://github.com/PSeitz/lz4_flex).
**Pros:**
- Fast! ⚡️
- Memory Safe! 🔒
- Uses libuv's threadpool! 🧵## Table of content
- [Installation](#installation)
- [Usage](#usage)
- [Compress](#compress)
- [Uncompress](#uncompress)
- [APIs](#apis)
- [Promises](#promises)
- [`compress`](#compress)
- [`uncompress`](#uncompress)
- [Sync](#sync)
- [`compressSync`](#compresssync)
- [`uncompressSync`](#uncompresssync)
- [Benchmarks](#benchmarks)
- [Performance](#performance)
- [Hardware](#hardware)
- [Results](#results)
- [Contributing](#contributing)
- [License](#license)## Installation
```sh
npm i lz4-napi
# OR
yarn add lz4-napi
```## Usage
### Compress
```js
const { readFile } = require('fs/promises');
const { compress } = require('lz4-napi');// if you support top-level await
const buffer = await readFile("./bigFile.dat");
const compressedBuffer = await compress(buffer)
// Store compressed buffer somewhere
```### Uncompress
```js
const { uncompress } = require('lz4-napi');// if you support top-level await
const compressedBuffer = await getFromSomeStorage();
const uncompressedBuffer = await uncompress(compressedBuffer)
// Do something with compressedBuffer!
```## APIs
### Promise
#### `compress`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array, dict?: string | Buffer) => Promise
```#### `uncompress`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array, dict?: string | Buffer) => Promise
```#### `compressFrame`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Promise
```#### `decompressFrame`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array) => Promise
```### Sync
#### `compressSync`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array, dict?: string | Buffer) => Buffer
```#### `uncompressSync`
```ts
(data: Buffer | string | ArrayBuffer | Uint8Array, dict?: string | Buffer) => Buffer
```## Performance
### Hardware
Benchmarks runs on the following hardware:
- Processor Name: i9 9900K
- Total Number of Cores: 8
- Hyper-Threading Technology: Enabled
- Memory: 32 GB### Benchmark
```sh
Running "Compress" suite...
Progress: 100%lz4:
911 ops/s, ±18.64% | 54.68% slowersnappy:
2 010 ops/s, ±19.23% | fastestgzip:
78 ops/s, ±18.76% | 96.12% slowerdeflate:
118 ops/s, ±20.42% | 94.13% slowerbrotli:
6 ops/s, ±0.21% | slowest, 99.7% slowerFinished 5 cases!
Fastest: snappy
Slowest: brotli
Running "Decompress" suite...
Progress: 100%lz4:
9 425 ops/s, ±12.50% | fastestsnappy:
3 900 ops/s, ±13.39% | 58.62% slowergzip:
823 ops/s, ±20.48% | slowest, 91.27% slowerdeflate:
1 350 ops/s, ±12.52% | 85.68% slowerbrotli:
979 ops/s, ±11.55% | 89.61% slowerFinished 5 cases!
Fastest: lz4
Slowest: gzip
Done in 61.20s.
```## Contributing
Project is pretty simple and straight forward for what is my needs, but if you have any idea you're welcome.
> This projects uses [conventional commit](https://commitlint.js.org/#/) so be sure to use standard commit format or PR won't be accepted
1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'feat(scope): some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## Acknowledgments
- [Brooooooklyn/snappy](https://github.com/Brooooooklyn/snappy) - Inspiration and project structure
## License
Distributed under the MIT License. See `LICENSE` for more information.