Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
The 'snappy' npm package is a Node.js binding for Google's Snappy compression library. It provides fast and efficient compression and decompression functionalities, making it suitable for applications that require high-speed data processing.
Compression
This feature allows you to compress a given input buffer using Snappy's compression algorithm. The code sample demonstrates how to compress a simple 'Hello, world!' string.
const snappy = require('snappy');
const input = Buffer.from('Hello, world!');
snappy.compress(input, (err, compressed) => {
if (err) throw err;
console.log('Compressed:', compressed);
});
Decompression
This feature allows you to decompress a previously compressed buffer. The code sample shows how to uncompress data and convert it back to its original form.
const snappy = require('snappy');
const compressed = Buffer.from('compressed data here');
snappy.uncompress(compressed, { asBuffer: true }, (err, original) => {
if (err) throw err;
console.log('Decompressed:', original.toString());
});
Stream Compression
This feature provides stream-based compression, which is useful for handling large files or data streams. The code sample demonstrates how to compress a file using streams.
const snappy = require('snappy');
const fs = require('fs');
const input = fs.createReadStream('input.txt');
const output = fs.createWriteStream('output.snappy');
input.pipe(snappy.compressStream()).pipe(output);
Stream Decompression
This feature provides stream-based decompression. The code sample shows how to decompress a file using streams.
const snappy = require('snappy');
const fs = require('fs');
const input = fs.createReadStream('output.snappy');
const output = fs.createWriteStream('decompressed.txt');
input.pipe(snappy.uncompressStream()).pipe(output);
The 'lz4' package provides bindings for the LZ4 compression algorithm, which is known for its high-speed compression and decompression. Compared to Snappy, LZ4 often offers better compression ratios but may be slightly slower in some scenarios.
The 'zlib' package is a core Node.js module that provides compression and decompression functionalities using the Deflate algorithm. While zlib offers good compression ratios, it is generally slower than Snappy and LZ4.
The 'brotli' package provides bindings for the Brotli compression algorithm, which is known for its high compression ratios and efficiency. Brotli is often used for web content compression but may be slower than Snappy in terms of speed.
snappy
!!! 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.
yarn add snappy
node12 | node14 | node16 | |
---|---|---|---|
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 | ✓ | ✓ | ✓ |
FreeBSD x64 | ✓ | ✓ | ✓ |
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>
Model Name: MacBook Pro
Model Identifier: MacBookPro15,1
Processor Name: 6-Core Intel Core i7
Processor Speed: 2.6 GHz
Number of Processors: 1
Total Number of Cores: 6
L2 Cache (per Core): 256 KB
L3 Cache: 12 MB
Hyper-Threading Technology: Enabled
Memory: 16 GB
Running "Compress" suite...
Progress: 25%
snappy:
1 426 ops/s, ±2.26%
gzip:
152 ops/s, ±1.54%
deflate:
155 ops/s, ±2.14%
brotli:
3 ops/s, ±3.43% | slowest, 99.79% slower
Finished 4 cases!
Fastest: snappy
Slowest: brotli
Running "Decompress" suite...
Progress: 25%
snappy:
2 771 ops/s, ±1.13%
gzip:
854 ops/s, ±6.99%
deflate:
877 ops/s, ±3.19%
brotli:
638 ops/s, ±2.31% | slowest, 76.98% slower
Finished 4 cases!
Fastest: snappy
Slowest: brotli
FAQs
Fastest Snappy compression library in Node.js
The npm package snappy receives a total of 143,158 weekly downloads. As such, snappy popularity was classified as popular.
We found that snappy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.