@openpgp/unbzip2-stream
v2.0.0
Published
streaming unbzip2 implementation in pure javascript for node and browsers
Readme
unbzip2-stream
streaming bzip2 decompressor in pure JS for Node and browsers.
In both environments, the library uses TransformStreams and Uint8Arrays.
Usage
Web
import unbzip2Stream from 'unbzip2-stream';
// decompress test.bz2 and output the result
const response = await fetch('./test.bz2');
const decompressedStream = unbzip2Stream(response.data);
for await(const chunk of decompressedStream) {
console.log(chunk);
}Node
const unbzip2Stream = require('unbzip2-stream');
const fs = require('fs');
// decompress test.bz2 and output the result
let stream = fs.createReadStream('./test.bz2');
stream = stream.Readable.toWeb(stream);
stream = unbzip2Stream(stream);
stream = stream.Readable.fromWeb(stream);
stream.pipe(process.stdout);Also see test/browser/download.js for a complete example of decompressing a file while downloading.
Tests
To run tests in Node:
npm run testTo run tests in PhantomJS
npm run browser-testAdditional Tests
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-testYou can now
npm run long-testAnd to run a test in chrome that downloads and decompresses a large binary file
npm run download-testOpen the browser's console to see the output.
