adm-zip
adm-zip copied to clipboard
writeZip fails if there are any directories
Fails at zipFile.js->compressToBuffer->entry.getCompressedData()
I'm using v0.4.4 of adm-zip (Ubuntu precise (12.04.4 LTS)) in a nodejs project. I find if I delete all directories that is the only way I get a write, of an empty zip... I logged-up compressToBuffer and found the error is at this call: var compressedData; try{ compressedData = entry.getCompressedData(); }catch(e){ console.log("exception: ", e); } Here is a log of this running. I even messed with doing a delete on the bin/ directory, but I get the same results. entryList.forEach entry: bin/ get compressedData get dataHeader get postHeader entryList.forEach entry: bin/flash.sh get compressedData exception: Invalid LOC header (bad signature)
If I find a fix I'll let you know. I should mention I get this exact behaviour doing nothing other than: var zip = new AdmZip(tempFileName); zip.writeZip("/tmp/fly.zip");
Made a very simple test script.
- Made a zip with only one file inside, no directory structure. - WORKED (writeZip)
- Made a folder with one file inside and added to the test zip - FAILED (exception: Invalid LOC header (bad signature))
+1
+1 same thing happens on mac
+1
+1
+1
+1 I have the same issue
I had a similar problem with some zip files. The zip.toBuffer() statement would work once, and fail on the second try. I found a workaround that might help some of you.
var ADMZIP = require('adm-zip');
var zipBad = new ADMZIP(response.Body); // where response.Body is the result of reading a 'net resource, but it could also be a local file - that is not the point of this snippet
var b1 = zipBad.toBuffer();
var b2 = zipBad.toBuffer(); // this fails with the exception: "Error: Invalid LOC header (bad signature)"
var tempBuffer = new ADMZIP(response.Body).toBuffer();
var zipGood = new ADMZIP(tempBuffer);
var b3 = zipGood.toBuffer();
var b4 = zipGood.toBuffer(); // works!
我对一些 zip 文件有类似的问题。zip.toBuffer() 语句将工作一次,并在第二次尝试时失败。我找到了一种可能对你们中的一些人有所帮助的解决方法。
var ADMZIP = require('adm-zip'); var zipBad = new ADMZIP(response.Body); // where response.Body is the result of reading a 'net resource, but it could also be a local file - that is not the point of this snippet var b1 = zipBad.toBuffer(); var b2 = zipBad.toBuffer(); // this fails with the exception: "Error: Invalid LOC header (bad signature)" var tempBuffer = new ADMZIP(response.Body).toBuffer(); var zipGood = new ADMZIP(tempBuffer); var b3 = zipGood.toBuffer(); var b4 = zipGood.toBuffer(); // works!
此处当有掌声