如何在node.js中解压文件

有一些untar库,但我不能让他们工作。

我的想法会是这样的

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

是这样的可用吗?

只是对这个答案的更新,而不是node-tar ,可以考虑使用tar-fs ,这会产生显着的性能提升,以及更好的接口。

 var tarFile = 'my-other-tarball.tar'; var target = './my-other-directory'; // extracting a directory fs.createReadStream(tarFile).pipe(tar.extract(target)); 

焦油stream模块是一个很好的模块:

 var tar = require('tar-stream') 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!') }); 
Interesting Posts