adm-zip: writeZip() throws "Invalid LOC header (bad signature)" error

This issue is occurring in version: 0.4.3 on Windows.

Initially noticed this occurred with jar files however I can reproduce it with other zips I had.

Examples: The kickstarter zip: http://www.99lime.com/downloads/ Apache tomcat zip: http://tomcat.apache.org/download-80.cgi

var AdmZip = require('adm-zip');
var jarZip = new AdmZip('WEB-INF\\lib\\snappy-java.jar');
jarZip.writeZip();

Produces

A:\myapp\node_modules\adm-zip\headers\entryHeader.js:113
                throw Utils.Errors.INVALID_LOC;
                                  ^
Invalid LOC header (bad signature)

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 31 (1 by maintainers)

Commits related to this issue

Most upvoted comments

NAVER - http://www.naver.com/

artworker@naver.com 님께 보내신 메일 <Re: [adm-zip] writeZip() throws “Invalid LOC header (bad signature)” error (#64)> 이 다음과 같은 이유로 전송 실패했습니다.


받는 사람이 회원님의 메일을 수신차단 하였습니다.


I got this error calling toBuffer() in nodejs 6.10.0

FYI: I used adm-zip because it seemed to be one of the few js libraries that allowed one to add files to existing zips.

However, I kept hitting this error, so I switched to JSZip. Works just fine for my use case (add a dynamically generated text file to an existing zip, and stream zip to user with node Express server).

There’s a workaround by migrating all entries to a new zip file (example in coffeescript):

existingZip = new Zip path
newZip = new Zip

for entry in existingZip.getEntries()
    if iWantToChangeThisFile
        content = change existingZip.readAsText entry, 'utf-8'
        buffer = new Buffer content, 'utf-8'
        newZip.addFile entry.entryName, buffer
    else
        newZip.addFile entry.entryName, existingZip.readFile entry

newZip.writeZip newPath

I’m runnng into this when I try to send my zip (which I’ve already parsed out as entries so belive the zip is fine) toBuffer():

    var buffZip = zip.toBuffer();

This generates:

    throw Utils.Errors.INVALID_LOC;
    Invalid LOC header (bad signature)

Running Win 7, Node 0.10.32 and adm-zip 0.4.4

Have the same issue invoking the .toBuffer() method with macOS generated zip-files.