Hi. I'm using jszip to zip 6 different folders with multiple files in each. The result of my code, is a generated file, but only some of the contents are there. If there's less folders, it seems to do better, but if there's something in each folder, I'm lucky to get 4 of the 6. Here's my code:
app.post('/zip', (req, res) =>{
console.log(req.body)
userName = req.body.userName
let zipPath = `./public/uploads/${userName}`
console.log("ZIP user name set to " + userName)
console.log("zip path set to: "+ zipPath)
let zip = new JSZip();
if (fs.existsSync(`${zipPath}/chrono`)){
let chronoFolder = zip.folder(`chrono`)
let chronofiles = fs.readdirSync(`./public/uploads/${userName}/chrono/`)
chronofiles.forEach(function(file){
chronoFolder.file(file, fs.readFileSync(`./${zipPath}/chrono/${file}`));
})
}
if (fs.existsSync(`${zipPath}/family`)){
let familyFolder = zip.folder(`family`)
let familyfiles = fs.readdirSync(`./public/uploads/${userName}/family/`)
familyfiles.forEach(function(file){
familyFolder.file(file, fs.readFileSync(`./${zipPath}/family/${file}`));
})
}
if (fs.existsSync(`${zipPath}/extended`)){
let extFolder = zip.folder(`extended`)
let extfiles = fs.readdirSync(`./public/uploads/${userName}/extended/`)
extfiles.forEach(function(file){
extFolder.file(file, fs.readFileSync(`./${zipPath}/extended/${file}`));
})
}
if (fs.existsSync(`${zipPath}/friends`)){
let friendsFolder = zip.folder(`friends`)
let friendsfiles = fs.readdirSync(`./public/uploads/${userName}/friends/`)
friendsfiles.forEach(function(file){
friendsFolder.file(file, fs.readFileSync(`./${zipPath}/friends/${file}`));
})
}
if (fs.existsSync(`${zipPath}/fun`)){
let funFolder = zip.folder(`fun`)
let funfiles = fs.readdirSync(`./public/uploads/${userName}/fun/`)
funfiles.forEach(function(file){
funFolder.file(file, fs.readFileSync(`./${zipPath}/fun/${file}`));
})
}
if (fs.existsSync(`${zipPath}/unsorted`)){
let unsortedFolder = zip.folder(`unsorted`)
let unsortedfiles = fs.readdirSync(`./public/uploads/${userName}/unsorted/`)
unsortedfiles.forEach(function(file){
unsortedFolder.file(file, fs.readFileSync(`./${zipPath}/unsorted/${file}`));
})
}
zip
.generateNodeStream({type:'nodebuffer',streamFiles:true})
.pipe(fs.createWriteStream(`public/uploads/${userName}/${userName}-photos.zip`))
.on('finish', function () {
console.log("photos.zip written.");
res.send(`http://localhost:8080/uploads/${userName}/${userName}-photos.zip`);
});
})
Hi. I'm using jszip to zip 6 different folders with multiple files in each. The result of my code, is a generated file, but only some of the contents are there. If there's less folders, it seems to do better, but if there's something in each folder, I'm lucky to get 4 of the 6. Here's my code: