Skip to content

Brooooooklyn/snappy

Folders and files

NameName
Last commit message
Last commit date
Nov 8, 2023
Jan 22, 2025
Jun 9, 2021
Mar 1, 2025
Aug 21, 2024
Aug 21, 2024
Sep 22, 2024
Dec 18, 2021
May 13, 2024
Jul 29, 2023
Jul 29, 2023
Mar 1, 2025
Jan 5, 2023
Jul 18, 2024
Jun 9, 2021
Aug 29, 2022
Jun 9, 2021
Sep 22, 2024
Aug 21, 2024
Oct 5, 2022
Mar 19, 2025
Aug 4, 2021
Jun 9, 2021
Aug 21, 2024
Dec 18, 2021
Mar 19, 2025

Repository files navigation

snappy

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

!!! For snappy@6.x and below, please go to 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