'Unzip the specific folder in NodeJS
Is there any way I can unzip the specific folder from the zip file via NodeJS.
I tried this
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();
}
});
But this work only for files. I want to look for specifc folder and unzip that.
Solution 1:[1]
var filename = req.files[0].filenam
var zippath = __dirname + "../../../../../public/uploads/pages/zip/"
var unzippath = __dirname + "../../../../../public/uploads/pages/"
fs.createReadStream(zippath + filename).pipe(unzipper.Extract({ path: unzippath }))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tyler2P |
