Giter Site home page Giter Site logo

linecode / lz4-napi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from antoniomuso/lz4-napi

0.0 1.0 0.0 476 KB

Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.

License: MIT License

Shell 0.40% JavaScript 55.22% Rust 20.41% TypeScript 23.97%

lz4-napi's Introduction

lz4-napi

Node.js NAPI Binding for LZ4 compression algorithm, powered by Rust napi-rs and lz4-flex.

Pros:

  • Fast! ⚡️
  • Memory Safe! 🔒
  • Uses libuv's threadpool! 🧵

Table of content

Installation

npm i lz4-napi
# OR
yarn add lz4-napi

Usage

Compress

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

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

(data: Buffer | string | ArrayBuffer | Uint8Array) => Promise<Buffer>

uncompress

(data: Buffer | ArrayBuffer | Uint8Array) => Promise<Buffer>

Sync

compressSync

(data: Buffer | string | ArrayBuffer | Uint8Array) => Buffer

uncompressSync

(data: Buffer | ArrayBuffer | Uint8Array) => 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

Running "Compress" suite...
Progress: 100%

  lz4:
    911 ops/s, ±18.64%     | 54.68% slower

  snappy:
    2 010 ops/s, ±19.23%   | fastest

  gzip:
    78 ops/s, ±18.76%      | 96.12% slower

  deflate:
    118 ops/s, ±20.42%     | 94.13% slower

  brotli:
    6 ops/s, ±0.21%       | slowest, 99.7% slower

Finished 5 cases!
  Fastest: snappy
  Slowest: brotli
Running "Decompress" suite...
Progress: 100%

  lz4:
    9 425 ops/s, ±12.50%   | fastest

  snappy:
    3 900 ops/s, ±13.39%   | 58.62% slower

  gzip:
    823 ops/s, ±20.48%     | slowest, 91.27% slower

  deflate:
    1 350 ops/s, ±12.52%   | 85.68% slower

  brotli:
    979 ops/s, ±11.55%     | 89.61% slower

Finished 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 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

License

Distributed under the MIT License. See LICENSE for more information.

lz4-napi's People

Contributors

antoniomuso avatar dependabot[bot] avatar simonecorsi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.