Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to untar file in node.js

Tags:

node.js

tar

There are some untar libraries, but I cannot get them working.

My idea would be something like

untar(bufferStreamOrFilePath).extractToDirectory("/path", function(err){})

Is something like this available?

like image 900
Almad Avatar asked Dec 03 '12 19:12

Almad


2 Answers

Just an update on this answer, instead of node-tar, consider using tar-fs which yields a significant performance boost, as well as a neater interface.

var tarFile = 'my-other-tarball.tar';
var target = './my-other-directory';

// extracting a directory
fs.createReadStream(tarFile).pipe(tar.extract(target));
like image 160
Yanick Rochon Avatar answered Oct 26 '22 22:10

Yanick Rochon


The tar-stream module is a pretty good one:

var tar = require('tar-stream')
var fs = require('fs') 

var extract = tar.extract();
extract.on('entry', function(header, stream, callback) {
    // make directories or files depending on the header here...
    // call callback() when you're done with this entry
});

fs.createReadStream("something.tar").pipe(extract)

extract.on('finish', function() {
    console.log('done!')
});
like image 39
B T Avatar answered Oct 26 '22 23:10

B T