Skip to content

openpgpjs/unbzip2-stream

 
 

Repository files navigation

npm version

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 test

To run tests in PhantomJS

npm run browser-test

Additional 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-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.

About

streaming unbzip2 implementatio in pure javascript for node and browsers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%