Create a zip with the files without any parent directory
Hi, I'd like to have all my files directly into the zip without any folder.
So If I do that...
zip.addLocalFile('asset1.png');
zip.addLocalFile('asset2.png');
zip.addLocalFile('asset3.png');
zip.writeZip('files.zip');
... then extract files.zip, I'd like to have directly the 3 assets and not
files/asset1.png
files/asset2.png
files/asset3.png
Thanks a lot
I know a workaround for this: read each file content as a buffer. Example with async :
async.each(files, function (file, next) {
fs.readFile(templateFilePath + '/' + file, function (err, buffer) {
if (err) return next(err);
zip.addFile(file, buffer);
next();
})
}, function (err) {
if (err) return done(err);
zip.writeZip(filePath, function (err, file) {
if (err) return done(err);
.
.
return done();
});
Thanks, but that doesn't fix it for me. I still get a root folder containing my files :s
Late to the party, but you just need a zipPath.
zip.addLocalFile('asset1.png', './');
zip.addLocalFile('asset2.png', './');
zip.addLocalFile('asset3.png', './');
zip.writeZip('files.zip');
https://github.com/cthackers/adm-zip/wiki/ADM-ZIP#void-addlocalfilestring-localpath-string-zippath
Was there ever a resolution to this? I need to use 'addLocalFolder' and I need all of the files to be at the root of the zip.
The following code puts all the files in a root directory "my-zip". Im using version 0.4.11.
const AdmZip = require("adm-zip");
const zip = new AdmZip();
zip.addLocalFolder("./sandbox/src/lib/", "./");
zip.writeZip("./spec/my-zip.zip");
Realized this is a difference between mac and linux. On my Mac, it automatically unzips into a directory the same name as zip file. When I unzip on linux, it works as expected.
Hope this saves someone else some time.