4

I want to extract .tar.bz2 like the following with tar.gz with node.js:

request.get("localhost/file.tar.gz")
.pipe(zlib.createGunzip())
.pipe(tar.Extract({path: "./test"}))
.on("error", function(err){
    console.log("Error on extract", err);
})
.on("end", function(){
    console.log("done.");
});

The part "zlib.createGunzip()" should be replaced by a bz2-deflator. Does anyone know a working package for this issue?

Thanks

remoe
  • 35
  • 1
  • 4

2 Answers2

3

Use https://github.com/regular/unbzip2-stream.

Then https://github.com/mafintosh/tar-fs.

Not my repo.

Example:

const fs = require('fs');
const bz2 = require('unbzip2-stream');
const tarfs = require('tar-fs');

fs.createReadStream('foo.tar.bz2').pipe(bz2()).pipe(tarfs.extract('data'));

Above example will extract foo.bar.bz2 into data/ directory.

kbridge4096
  • 901
  • 1
  • 11
  • 22
  • If anyone is unzipping it as a different file type, instead of `.pipe(tarfs.extract('data'))`, use `.pipe(fs.createWriteStream('data/filename.extension'))` – Kevin Danikowski Sep 11 '21 at 14:51
0

They discuss the same issue here also: https://github.com/cscott/seek-bzip/issues/1

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56