New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

node-bzip2

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-bzip2

NodeJS bindings for BZip2 (libbz2)

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
0
Created
Source

NPM

node-bzip2

NodeJS bindings for BZip2 (libbz2).

This package will compile the BZip2 library from source and link against it, exposing functions for compressing and decompressing data using the BZip2 algorithm in NodeJS.

This package does not work on the web and is designed for use in NodeJS only.

Installation

npm install node-bzip2 --save

Usage

The package exposes two functions: compress and decompress (and their respective async versions compressAsync and decompressAsync).

Both functions can take a string, Buffer, or typed array as input and return a Buffer containing the compressed or decompressed data.

Additional options such as compression level and buffering behavior can be passed as an optional second argument, explained in the respective functions' JSDocs.

const bzip2 = require('node-bzip2');

// Compress some data
const compressedBytes = bzip2.compress('Hello, world!', { level: 9, buffering: 'auto' });

// Decompress the data
const decompressedBytes = bzip2.decompress(compressedBytes, { small: false });

// Decode the decompressed data as a UTF-8 string
const decompressed = (new TextDecoder('utf8')).decode(decompressedBytes);

console.log(decompressed); // Hello, world!

You can also use the async functions to compress and decompress data asynchronously:

const bzip2 = require('node-bzip2');

// Compress some data
const compressedBytes = await bzip2.compressAsync('Hello, world!', { level: 9, buffering: 'auto' });

// Decompress the data
const decompressedBytes = await bzip2.decompressAsync(compressedBytes, { small: false });

// Decode the decompressed data as a UTF-8 string
const decompressed = (new TextDecoder('utf8')).decode(decompressedBytes);

console.log(decompressed); // Hello, world!

Keywords

bzip2

FAQs

Package last updated on 07 Feb 2025

Did you know?

Socket

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.

Install

Related posts