Burro
Burro is a useful creature that auto-packages objects in length-prefixed JSON byte streams.
Example
var burro = require("burro"),
stream = require("stream");
var dummy = new stream.PassThrough();
var socket = burro.wrap(dummy);
socket.write({message: "どもうありがとう!", from: "japan", to: "usa"});
socket.write({message: "thank you!", from: "usa", to: "japan"});
var parser = new stream.Transform({objectMode: true});
parser._transform = function _transform (obj, encoding, done) {
var str = obj.from + " says: " + obj.message + "\n";
this.push(str);
done();
};
socket.pipe(parser).pipe(process.stdout);
Output
japan says: どもうありがとう!
usa says: thank you!
Tests
requires: npm install mocha
Burro is a pretty versatile beast and can even handle very large payloads.
See the tests for more details.