binary-parse-stream
Advanced tools
Comparing version 1.2.1 to 1.2.2
70
index.js
@@ -6,4 +6,6 @@ 'use strict'; | ||
, inherits = require('util').inherits | ||
, Readable = require('readable') | ||
, abs = Math.abs | ||
var One = exports.One = -1 | ||
exports.One = -1 | ||
@@ -16,54 +18,36 @@ inherits(BinaryParseStream, TransformStream) | ||
this._queue = null | ||
this._needed = 0 | ||
this._single = false | ||
this._parser = this._parse() | ||
this.__read = Readable(Buffer(0)) | ||
this.__restart() | ||
} | ||
BinaryParseStream.prototype._transform = function(fresh, encoding, cb) { | ||
var queue = this._queue === null | ||
? fresh | ||
: Buffer.concat(this._queue, fresh) | ||
BinaryParseStream.prototype._transform = function(fresh, encoding, cb) { var self = this | ||
this.__read.push(fresh) | ||
var needed = this._needed | ||
, single = this._single | ||
while (this.__read.able >= abs(this.__needed)) { | ||
var ret | ||
, chunk = this.__read(this.__needed) | ||
while (queue.length >= needed) { | ||
var chunk = queue.slice(0, needed) | ||
queue = queue.slice(needed) | ||
try { ret = this.__parser.next(chunk) } | ||
catch (e) { | ||
this.emit('error', e) | ||
this.__restart() | ||
continue | ||
} | ||
var ret | ||
, err | ||
try { | ||
if (single) | ||
ret = this._parser.next(chunk[0]) | ||
else | ||
ret = this._parser.next(chunk) | ||
if (ret.done) { | ||
this.push(ret.value) | ||
this.__restart() | ||
continue | ||
} | ||
catch (e) { | ||
err = e | ||
ret = { done: true } | ||
} | ||
if (!ret.done) { | ||
var value = ret.value | ||
single = value === One | ||
needed = single | ||
? 1 | ||
: value | ||
} | ||
else { | ||
if (err) | ||
this.emit('error', err) | ||
else | ||
this.push(ret.value) | ||
needed = 0 | ||
this._parser = this._parse() | ||
} | ||
this.__needed = ret.value | ||
} | ||
this._queue = queue | ||
this._needed = needed | ||
this._single = single | ||
return cb() | ||
} | ||
BinaryParseStream.prototype.__restart = function() { | ||
this.__needed = 0 | ||
this.__parser = this._parse() | ||
} |
{ | ||
"name": "binary-parse-stream", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Painless streaming binary protocol parsers using generators.", | ||
@@ -22,3 +22,6 @@ "main": "index.js", | ||
}, | ||
"homepage": "https://github.com/nathan7/binary-parse-stream" | ||
"homepage": "https://github.com/nathan7/binary-parse-stream", | ||
"dependencies": { | ||
"readable": "~1.1.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
3187
1
40
+ Addedreadable@~1.1.2
+ Addedreadable@1.1.3(transitive)