stUrb
stUrb

Reputation: 6832

Unzipping with zlib in Node.js results in incorrect header error

In short I'm trying to read a .zip file from my file system, deflate the zip-file and them stream it with xml-stream to do some things with the contents in the file.

I thought this would be fairly simple and started with this:

var fs        = require('fs')
    , XmlStream = require('xml-stream')
    , zlib = require('zlib');

//- read the file and buffer it.
    var path = '../path/to/some.zip';
    var fileBuffer = fs.readFileSync(path, { encoding: 'utf8' });

//- use zlib to unzip it
    zlib.gunzip(fileBuffer, function(err, buffer) {
       if (!err) {
         console.log(buffer.toString());
       }
       console.log(err);
    });

But this results in a

 { [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR' }

Changing the encoding or the method (.unzip, .gunzip or .inflate) isn't working either.

What am I missing here?

Upvotes: 1

Views: 6372

Answers (2)

Evgenii
Evgenii

Reputation: 3430

I'm using zlib.unzip instead zlib.gunzip

Upvotes: 0

RickN
RickN

Reputation: 13500

Gzip is not zip. They're different compression formats, just like RAR is. The error indicates that what you're trying to read is not a gzipped file.

You can use a different library, such as JSZip.

Upvotes: 1

Related Questions