1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Simplify DelimitedStream a little.

This commit is contained in:
Simo Kinnunen 2014-07-28 18:57:37 +09:00
parent 34ff1efb43
commit 437596e6c6

View file

@ -17,20 +17,18 @@ DelimitedStream.prototype._transform = function(chunk, encoding, done) {
while (this._buffer.length) {
if (this._readingLength) {
var byte = this._buffer[0]
if (byte & (1 << 7)) {
this._length += (byte & 0x7f) << (7 * this._lengthIndex)
if (byte & (1 << 7)) {
this._lengthIndex += 1
this._readingLength = true
}
else {
this._length += (byte & 0x7f) << (7 * this._lengthIndex)
this._lengthIndex = 0
this._readingLength = false
}
this._buffer = this._buffer.slice(1)
}
if (!this._readingLength) {
else {
if (this._length <= this._buffer.length) {
this.push(this._buffer.slice(0, this._length))
this._buffer = this._buffer.slice(this._length)