Comparing version 3.1.2 to 3.1.3
@@ -136,3 +136,2 @@ /* jshint node: true */ | ||
this._index = 0; // Next block index. | ||
this._pending = 0; // Number of blocks undergoing decompression. | ||
this._needPush = false; | ||
@@ -143,4 +142,4 @@ this._finished = false; | ||
this._finished = true; | ||
if (!this._pending) { | ||
this.push(null); | ||
if (this._needPush) { | ||
this._read(); | ||
} | ||
@@ -214,18 +213,25 @@ }); | ||
var nBlocks = 1; | ||
var block; | ||
while ((block = tryReadBlock(tap))) { | ||
nBlocks++; | ||
if (!this._syncMarker.equals(block.sync)) { | ||
// TODO: Maybe improve error handling to try and recover other blocks. | ||
cb(new Error('invalid sync marker')); | ||
return; | ||
} | ||
this._decompress(block.data, this._createBlockCallback()); | ||
this._decompress(block.data, this._createBlockCallback(chunkCb)); | ||
} | ||
chunkCb(); | ||
cb(); | ||
function chunkCb() { | ||
if (!--nBlocks) { | ||
cb(); | ||
} | ||
} | ||
}; | ||
BlockDecoder.prototype._createBlockCallback = function () { | ||
BlockDecoder.prototype._createBlockCallback = function (cb) { | ||
var self = this; | ||
var index = this._index++; | ||
this._pending++; | ||
@@ -235,10 +241,9 @@ return function (err, data) { | ||
self.emit('error', err); | ||
return; | ||
} else { | ||
self._queue.push(new BlockData(index, data)); | ||
if (self._needPush) { | ||
self._read(); | ||
} | ||
} | ||
self._pending--; | ||
self._queue.push(new BlockData(index, data)); | ||
if (self._needPush) { | ||
self._needPush = false; | ||
self._read(); | ||
} | ||
cb(); | ||
}; | ||
@@ -248,2 +253,4 @@ }; | ||
BlockDecoder.prototype._read = function () { | ||
this._needPush = false; | ||
var tap = this._blockTap; | ||
@@ -253,3 +260,3 @@ if (tap.pos >= tap.buf.length) { | ||
if (!data) { | ||
if (this._finished && !this._pending) { | ||
if (this._finished) { | ||
this.push(null); | ||
@@ -256,0 +263,0 @@ } else { |
{ | ||
"name": "avsc", | ||
"version": "3.1.2", | ||
"description": "Blazing fast serialization", | ||
"version": "3.1.3", | ||
"description": "Blazingly fast serialization", | ||
"homepage": "https://github.com/mtth/avsc", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
106872
3434