如何解压Node.js中的gzip文件

我想在Node.js中解压缩gzip文件我试过[一些]软件包,但没有任何工作。 你能提供一个可以解压Node.js中的gzip文件的示例代码的包吗?

gunzip-file节点包工作正常!

做:

 npm install gunzip-file 

然后:

 'use strict' const gunzip = require('gunzip-file') // 'sitemap.xml.gz' - source file // 'sitemap.xml' - destination file // () => { ... } - notification callback gunzip('sitemap.xml.gz', 'sitemap.xml', () => { console.log('gunzip done!') }) 

最后,在你的shell中运行Node。

我会build议使用zlib.Gunzip

函数原型是zlib.Gunzip(buf, callback) 。 第一个参数是将原始存档数据作为要提取的缓冲区 ,第二个参数是接受两个参数(结果和错误)的callback。

一个实现将是:

 zlib.Gunzip(raw_data, function (error, result) { if (error) throw error; // Access data here through result as a Buffer }) 

你可以使用tar.gz npm包来解决这个问题。

编写下面的方法将其提取到特定的path:

 targz().extract('/bkp/backup.tar.gz', '/home/myuser') .then(function(){ console.log('Job done!'); }) .catch(function(err){ console.log('Something is wrong ', err.stack); }); 

有关更多详细信息,您可以按照此链接