Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

snappy

Brooooooklyn1.1mMIT7.2.2TypeScript support: included

Fastest Snappy compression library in Node.js

snappy, snap, compression, compress, napi-rs, NAPI, N-API, Rust, Node-API, node-addon, node-addon-api

readme

snappy

https://github.com/Brooooooklyn/snappy/actions Install size

!!! For `snappy@6.xand below, please go to [node-snappy`](https://github.com/kesla/node-snappy).

More background about the 6-7 changes, please read this, Thanks @kesla .

🚀 Help me to become a full-time open-source developer by sponsoring me on Github

Fastest Snappy compression library in Node.js, powered by napi-rs and rust-snappy.

For small size data, snappyjs is faster, and it support browser. But it doesn't have async API, which is important for Node.js program.

Install this package

yarn add snappy

Support matrix

| | node12 | node14 | node16 | node18 | | ---------------- | ------ | ------ | ------ | ------ | | Windows x64 | ✓ | ✓ | ✓ | ✓ | | Windows x32 | ✓ | ✓ | ✓ | ✓ | | Windows arm64 | ✓ | ✓ | ✓ | ✓ | | macOS x64 | ✓ | ✓ | ✓ | ✓ | | macOS arm64 | ✓ | ✓ | ✓ | ✓ | | Linux x64 gnu | ✓ | ✓ | ✓ | ✓ | | Linux x64 musl | ✓ | ✓ | ✓ | ✓ | | Linux arm gnu | ✓ | ✓ | ✓ | ✓ | | Linux arm64 gnu | ✓ | ✓ | ✓ | ✓ | | Linux arm64 musl | ✓ | ✓ | ✓ | ✓ | | Android arm64 | ✓ | ✓ | ✓ | ✓ | | Android armv7 | ✓ | ✓ | ✓ | ✓ | | FreeBSD x64 | ✓ | ✓ | ✓ | ✓ |

API

export function compressSync(input: Buffer | string | ArrayBuffer | Uint8Array): Buffer
export function compress(input: Buffer | string | ArrayBuffer | Uint8Array): Promise<Buffer>
export function uncompressSync(compressed: Buffer): Buffer
export function uncompress(compressed: Buffer): Promise<Buffer>

Performance

Hardware

OS: Windows 11 x86_64
Host: Micro-Star International Co., Ltd. MS-7C35
Kernel: 10.0.22000
Terminal: Windows Terminal
CPU: AMD Ryzen 9 5950X (32) @ 3.400GHz
Memory: 32688MiB

Result

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

  snappy:
    4 220 ops/s, ±0.66%   | fastest

  snappy-v6:
    2 018 ops/s, ±0.84%   | 52.18% slower

  gzip:
    233 ops/s, ±0.52%     | slowest, 94.48% slower

  deflate:
    235 ops/s, ±0.45%     | 94.43% slower

  brotli:
    7 ops/s, ±0.51%       | slowest, 99.85% slower

Finished 4 cases!
  Fastest: snappy
  Slowest: brotli

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

  snappy:
    8 528 ops/s, ±1.03%   | fastest

  snappy-v6:
    6 357 ops/s, ±1.76%   | 25.46% slower

  gzip:
    1 406 ops/s, ±1.80%   | slowest, 83.51% slower

  deflate:
    1 435 ops/s, ±1.88%   | 83.17% slower

  brotli:
    1 208 ops/s, ±1.50%   | slowest, 86.99% slower

Finished 4 cases!
  Fastest: snappy
  Slowest: brotli

changelog

7.2.2 (2022-11-13)

Bug Fixes

  • unref buffer when compress/uncompress synchronously faild (#105) (8cfc521)

7.2.1 (2022-10-23)

Bug Fixes

7.2.0 (2022-10-05)

Features

  • provide copyOutputData to compatible with electron >= 21 (772abc9)

7.1.2 (2022-08-09)

Bug Fixes

  • compatible issues with centos:7 and void Linux (dbd61db)

7.1.1 (2021-12-22)

Bug Fixes

  • override the package name in generated index.js (42346fd)

7.1.0 (2021-12-22)

Features

7.0.5 (2021-11-06)

Bug Fixes

  • decompress: cast input to buffer (9bdf8f3), closes #38

7.0.4 (2021-10-28)

Bug Fixes

  • avoid copy input buffer (00cdd39)

7.0.3 (2021-08-27)

Bug Fixes

  • remove Ref usage to avoid memory leak (c89bb2e)

7.0.2 (2021-08-11)

Bug Fixes

  • missing asBuffer option in uncompress/uncompressSync (ac573f8)

7.0.1 (2021-08-04)

Bug Fixes

  • native binding package name (6dc09af)

7.0.0 (2021-08-04)

Change package name to snappy #16 .

1.0.2 (2021-07-22)

Bug Fixes

  • linux aarch64 musl build (1a9a475)

1.0.1 (2021-06-10)

Performance Improvements

  • mimalloc as global allocator (3fbab59)

1.0.0 (2021-06-10)

Features

  • implement compress and uncompress (df2ccd2)