streaming unbzip2 implementation in pure javascript for node and browsers

Usage no npm install needed!

<script type="module">
  import unbzip2Stream from 'https://cdn.skypack.dev/unbzip2-stream';


npm version


streaming bzip2 decompressor 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

Also see test/browser/download.js for an example of decompressing a file while downloading.

Or, using a <script> tag

<script src="https://npm-cdn.info/unbzip2-stream/dist/unbzip2-stream.min.js"></script>
    var myStream = window.unbzip2Stream();
    // now pipe stuff through it (see above)


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.