我想在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!')
})
zlib
已经在 Node v0.5.8 中添加,该版本于2011年末发布。这比此答案发布的时间早了许多年。无论是2012年、2017年还是2022年,都不需要第三方包 =) - Mike 'Pomax' Kamermanszlib.Gunzip
。zlib.Gunzip(buf,callback)
。第一个参数是您想要提取的原始归档数据作为缓冲区,第二个参数是接受两个参数(结果和错误)的回调函数。zlib.Gunzip(raw_data, function (error, result) {
if (error) throw error;
// Access data here through result as a Buffer
})
raw_data
的? - Antoine C.在一个目录中解压文件:
压缩目录中的文件:
更多信息: https://medium.com/@harrietty/zipping-and-unzipping-files-with-nodejs-375d2750c5e4您可以使用tar.gz
npm包来解决这个问题。
编写以下方法将其提取到特定路径:
targz().extract('/bkp/backup.tar.gz', '/home/myuser')
.then(function(){
console.log('Job done!');
})
.catch(function(err){
console.log('Something is wrong ', err.stack);
});
如需更多详细信息,请访问链接