adm-zip icon indicating copy to clipboard operation
adm-zip copied to clipboard

writeZip fails if there are any directories

Open neillindberg opened this issue 11 years ago • 9 comments

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");

neillindberg avatar Jun 03 '14 20:06 neillindberg

Made a very simple test script.

  1. Made a zip with only one file inside, no directory structure. - WORKED (writeZip)
  2. Made a folder with one file inside and added to the test zip - FAILED (exception: Invalid LOC header (bad signature))

neillindberg avatar Jun 03 '14 20:06 neillindberg

+1

astrotars avatar Jul 29 '15 21:07 astrotars

+1 same thing happens on mac

peter-mach avatar Oct 31 '16 10:10 peter-mach

+1

lcolman avatar Nov 21 '16 12:11 lcolman

+1

mn4367 avatar May 30 '17 16:05 mn4367

+1

thisispete avatar Oct 05 '17 00:10 thisispete

+1 I have the same issue

minhdtb avatar Oct 20 '17 08:10 minhdtb

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!

pbnelson avatar Nov 02 '18 21:11 pbnelson

我对一些 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!

此处当有掌声

xivcm avatar Jun 02 '22 04:06 xivcm