Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
unbzip2-stream
Advanced tools
streaming unbzip2 implementatio in pure javascript for node and browsers
The unbzip2-stream npm package is a Node.js library used for decompressing data in the bzip2 format. It is particularly useful for handling large bzip2 files or streams, such as those downloaded from the internet or read from a file system, by decompressing them on-the-fly.
Decompress bzip2 file
This code demonstrates how to decompress a bzip2 compressed file using unbzip2-stream. It reads a bzip2 file, decompresses it, and writes the decompressed data to a new file.
const fs = require('fs');
const bunzip2 = require('unbzip2-stream');
fs.createReadStream('path/to/compressed-file.bz2')
.pipe(bunzip2())
.pipe(fs.createWriteStream('path/to/decompressed-file'));
Decompress bzip2 stream
This example shows how to decompress a bzip2 stream from a URL and pipe the output directly to the standard output. This is useful for processing data on-the-fly without storing it.
const request = require('request');
const bunzip2 = require('unbzip2-stream');
request('http://example.com/file.bz2')
.pipe(bunzip2())
.pipe(process.stdout);
node-bzip is another npm package that provides bzip2 compression and decompression functionalities. Compared to unbzip2-stream, node-bzip offers both compression and decompression, whereas unbzip2-stream is focused only on decompression.
compressjs is a package that includes bzip2 compression and decompression among other compression algorithms. It provides a broader range of compression algorithms than unbzip2-stream, making it more versatile if multiple compression methods are needed.
streaming bzip2 compresser in pure JS for Node and browserify.
When browserified, the stream emits instances of feross/buffer instead of raw Uint8Arrays to have a consistant API across browsers and Node.
var bz2 = require('unbzip2-stream');
var fs = require('fs');
// decompress test.bz2 and output the result
fs.createReadStream('./test.bz2').pipe(bz2()).pipe(process.stdout);
Also see test/browser/download.js for an example of decompressing a file while downloading.
To run tests in Node:
npm run test
To run tests in PhantomJS
npm run browser-test
There are two more tests that specifically test decompression of a very large file. Because I don't want to include large binary files in this repository, the files are created by running an npm script.
npm run prepare-long-test
You can now
npm run long-test
And to run a test in chrome that downloads and decompresses a large binary file
npm run download-test
Open the browser's console to see the output.
FAQs
streaming unbzip2 implementation in pure javascript for node and browsers
The npm package unbzip2-stream receives a total of 6,094,057 weekly downloads. As such, unbzip2-stream popularity was classified as popular.
We found that unbzip2-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.