how to rename zip file nodejs

Solutions on MaxInterview for how to rename zip file nodejs by the best coders in the world

showing results for - "how to rename zip file nodejs"
Sara
16 Aug 2019
1var AdmZip = require('adm-zip');
2
3//create a zip object to hold the new zip files
4var newZip = new AdmZip();
5
6// reading archives
7var zip = new AdmZip('somePath/download.zip');
8var zipEntries = zip.getEntries(); // an array of ZipEntry records
9
10zipEntries.forEach(function(zipEntry) {
11    var fileName = zipEntry.entryName;
12    var fileContent = zip.readAsText(fileName)
13    //Here remove the top level directory
14    var newFileName = fileName.substring(fileName.indexOf("/") + 1);
15
16    newZip.addFile(newFileName, fileContent, '', 0644 << 16);        
17});
18
19newZip.writeZip('somePath/upload.zip');  //write the new zip 
20