如何从压缩目录中提取一个文件? Zlib没有任何文件浏览功能,所以我不知道该使用什么。
答案 0 :(得分:3)
您可以使用EvanOxfeld/node-unzip
解析zip文件内容:
var fs = require('fs')
var unzip = require('unzip')
var path = require('path')
var mkdir = require('mkdirp')
fs.createReadStream('./archive.zip')
.pipe(unzip.Parse())
.on('entry', function (entry) {
var fileName = entry.path
var type = entry.type
if (type==='File' && fileName === 'dir/fileInsideDir.txt') {
var fullPath = __dirname + '/output/' + path.dirname( fileName )
fileName = path.basename( fileName )
mkdir.sync(fullPath)
entry.pipe(fs.createWriteStream( fullPath + '/' + fileName ))
} else {
entry.autodrain()
}
})