frame-stream
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -19,3 +19,3 @@ 'use strict' | ||
this.buffer = null | ||
this.frameLength = 0 | ||
this.frameLength = -1 | ||
this.framePos = 0 | ||
@@ -30,10 +30,10 @@ | ||
while (chunk.length > 0) { | ||
var start = 0 | ||
var start = this.opts.lengthSize | ||
if (this.framePos === 0) { | ||
if (this.buffer) { | ||
chunk = Buffer.concat([this.buffer, chunk]) | ||
this.buffer = null | ||
} | ||
if (this.buffer) { | ||
chunk = Buffer.concat([this.buffer, chunk]) | ||
this.buffer = null | ||
} | ||
if (this.frameLength < 0) { | ||
if (chunk.length < this.opts.lengthSize) { | ||
@@ -54,4 +54,4 @@ this.buffer = chunk | ||
} | ||
start = this.opts.lengthSize | ||
} else if (this.opts.unbuffered) { | ||
start = 0 | ||
} | ||
@@ -63,7 +63,5 @@ | ||
end = Math.min(end, chunk.length) | ||
} else { | ||
if (chunk.length < end) { | ||
this.buffer = chunk | ||
return cont() | ||
} | ||
} else if (chunk.length < end) { | ||
this.buffer = chunk | ||
return cont() | ||
} | ||
@@ -80,2 +78,3 @@ | ||
if (buf.frameEnd) { | ||
this.frameLength = -1 | ||
this.framePos = 0 | ||
@@ -82,0 +81,0 @@ } |
{ | ||
"name": "frame-stream", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Length-prefixed message framing for Node.js streams.", | ||
@@ -5,0 +5,0 @@ "keywords": ["socket", "tcp", "framing", "streams"], |
@@ -75,3 +75,3 @@ # frame-stream | ||
[npm]: http://img.shields.io/npm/v/frame-stream.svg?style=flat | ||
[travis]: http://img.shields.io/travis/rkusa/frame-stream.svg?style=flat | ||
[npm]: http://img.shields.io/npm/v/frame-stream.svg?style=flat-square | ||
[travis]: http://img.shields.io/travis/rkusa/frame-stream.svg?style=flat-square |
10357