From 5c938503f9c1bd78711e575f87e8c222ffb38d66 Mon Sep 17 00:00:00 2001 From: TimNZ Date: Fri, 11 Oct 2013 12:05:53 +1300 Subject: [PATCH 1/2] Move emit('entry') to after fileDescriptor has been read and we have size info --- lib/parse.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/parse.js b/lib/parse.js index e9930c5..483a344 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -109,9 +109,6 @@ Parse.prototype._readFile = function () { } var hasEntryListener = self._hasEntryListener; - if (hasEntryListener) { - self.emit('entry', entry); - } self._pullStream.pull(vars.extraFieldLength, function (err, extraField) { if (err) { @@ -166,6 +163,7 @@ Parse.prototype._readFile = function () { self._pullStream.unpipe(); self._pullStream.prepend(extra); self._processDataDescriptor(entry); + self.emit('entry', entry); }); return this.push(null); }); From fcc090b52ebef23909d237326c98adb362fe63e6 Mon Sep 17 00:00:00 2001 From: TimNZ Date: Fri, 11 Oct 2013 15:29:38 +1300 Subject: [PATCH 2/2] Update parse.js --- lib/parse.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/parse.js b/lib/parse.js index 483a344..a0d0474 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -139,6 +139,7 @@ Parse.prototype._readFile = function () { entry.size = vars.uncompressedSize; if (hasEntryListener) { entry.on('finish', self._readRecord.bind(self)); + self.emit('entry', entry); self._pullStream.pipe(vars.compressedSize, inflater).pipe(entry); } else { self._pullStream.drain(vars.compressedSize, function (err) { @@ -163,7 +164,7 @@ Parse.prototype._readFile = function () { self._pullStream.unpipe(); self._pullStream.prepend(extra); self._processDataDescriptor(entry); - self.emit('entry', entry); + }); return this.push(null); }); @@ -194,6 +195,8 @@ Parse.prototype._processDataDescriptor = function (entry) { .vars; entry.size = vars.uncompressedSize; + if (self._hasEntryListener) + self.emit('entry', entry); self._readRecord(); }); };