diff --git a/lib/parse.js b/lib/parse.js index ebbf0297..4b0420aa 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -155,19 +155,18 @@ Parse.prototype._readFile = function () { var descriptorSig = new Buffer(4); descriptorSig.writeUInt32LE(0x08074b50, 0); - var matchStream = new MatchStream({ pattern: descriptorSig }, function (buf, matched, extra) { + var matchStream = new MatchStream({ pattern: descriptorSig }, function (buf, matched) { + if (!matched) { + return hasEntryListener ? this.push(buf) : null; + } + self._pullStream.unpipe(); if (hasEntryListener) { - if (!matched) { - return this.push(buf); - } this.push(buf); } - setImmediate(function() { - self._pullStream.unpipe(); - self._pullStream.prepend(extra); - self._processDataDescriptor(entry); - }); - return this.push(null); + this.end(); + }, function (extra) { + self._pullStream.prepend(extra); + self._processDataDescriptor(entry); }); self._pullStream.pipe(matchStream); @@ -240,7 +239,7 @@ Parse.prototype._readCentralDirectoryFileHeader = function () { if (err) { return self.emit('error', err); } - return self._readRecord(); + return setImmediate(self._readRecord.bind(self)); }); }); }); diff --git a/package.json b/package.json index e030e029..906f8d62 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "binary": "~0.3.0", "readable-stream": "~1.0.0", "setimmediate": "~1.0.1", - "match-stream": "0.0.1" + "match-stream": "git://github.com/EvanOxfeld/match-stream.git#callback-on-finish-wip" }, "devDependencies": { "tap": "~0.3.0",