packet-stream-codec
Advanced tools
Comparing version 1.0.0 to 1.1.0
17
index.js
@@ -7,2 +7,3 @@ | ||
var GOODBYE = 'GOODBYE' | ||
var isBuffer = Buffer.isBuffer | ||
@@ -20,2 +21,8 @@ | ||
//final packet | ||
if(isString(msg) && msg === GOODBYE) { | ||
head.fill(0) | ||
return [head, null] | ||
} | ||
if(isString(value)) { | ||
@@ -78,3 +85,4 @@ flags = STRING | ||
this.queue(c[0]) | ||
this.queue(c[1]) | ||
if(c[1] !== null) | ||
this.queue(c[1]) | ||
}) | ||
@@ -84,3 +92,3 @@ } | ||
function decode () { | ||
var reader = Reader() | ||
var reader = Reader(), ended = false | ||
@@ -91,2 +99,3 @@ return function (read) { | ||
return function (abort, cb) { | ||
if(ended) return cb(true) | ||
if(abort) return reader.abort(abort, cb) | ||
@@ -96,2 +105,6 @@ reader.read(9, function (err, head) { | ||
var msg = decodeHead(head) | ||
if(msg.length === 0) { //final packet | ||
ended = true | ||
return cb(null, GOODBYE) | ||
} | ||
reader.read(msg.length, function (err, body) { | ||
@@ -98,0 +111,0 @@ if(err) return cb(err) |
{ | ||
"name": "packet-stream-codec", | ||
"description": "binary codec for packet-stream", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/dominictarr/packet-stream-codec", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -12,3 +12,5 @@ # packet-stream-buffers | ||
the protocol sends a fixed size header, and then a buffer. | ||
The protocol sends zero or more header:body pairs, | ||
then a final header that is all zeros. | ||
``` | ||
@@ -19,2 +21,3 @@ ( | ||
) * | ||
[zeros (9 bytes)] | ||
``` | ||
@@ -21,0 +24,0 @@ |
@@ -24,3 +24,4 @@ | ||
{req: 2, stream: true, end: true, value: true}, //a stream packet | ||
{req: -2, stream: true, end: true, value: true} //a stream response | ||
{req: -2, stream: true, end: true, value: true}, //a stream response | ||
"GOODBYE" | ||
] | ||
@@ -34,8 +35,9 @@ | ||
t.equal(msg.length, c[1].length) | ||
msg = psc.decodeBody(c[1], msg) | ||
delete msg.length | ||
delete msg.type | ||
t.deepEqual(e, msg) | ||
if(c[1]) { | ||
t.equal(msg.length, c[1].length) | ||
msg = psc.decodeBody(c[1], msg) | ||
delete msg.length | ||
delete msg.type | ||
t.deepEqual(e, msg) | ||
} | ||
}) | ||
@@ -42,0 +44,0 @@ t.end() |
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
7346
168
37