[英]Unzip the zip file and exclude the root directory in NodeJS
是否有任何库可以在解压缩时排除根目录。
例如zip文件包含-根目录-第一个文件-第二个文件-第三个文件
我想排除根目录。
我建议使用解压缩包。
只需提取您要查找的内容:
const unzipper = require('unzipper');
const fs = require('fs');
fs.createReadStream('path/to/archive.zip') // Your zip file
.pipe(unzipper.Parse())
.on('entry', function (entry) {
const fileName = entry.path;
const type = entry.type; // 'Directory' or 'File'
// file_name1, file_name1 are files which you are looking for
if (type === 'File' && ['file_name1', 'file_name1'].indexOf(fileName) >= 0) {
entry.pipe(fs.createWriteStream('output/path/' + fileName)); // Output folder of unzip process
} else {
entry.autodrain();
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.