Turn any binary stream into an object stream
npm install net-object-streamTurn any binary stream into an object stream, with multiple codec support
``js
'use strict'
var net = require('net')
var nos = require('net-object-stream')
var through2 = require('through2')
var pump = require('pump')
var server = net.createServer(function (original) {
var stream = nos(original)
pump(stream, through2.obj(), stream)
})
server.listen(4200, function () {
var stream = nos(net.connect(4200))
stream.end({ hello: 'world' })
stream.on('data', console.log)
stream.on('end', server.close.bind(server))
})
`
Wraps stream into a Duplex object stream, recognized opts:
* codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
Creates an encoder for the netObjectStream protocol, recognized opts:
* codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
Creates a decoder for the netObjectStream protocol, recognized opts:
* codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
Creates a parser for the netObjectStream protocol, recognized opts:
* codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
The parser have a parser.parse(buf) function to add data to id.'message'
It will emit events when it is able to parse an object.
Write msg to the given stream, recognized options:
* codec: an object with a encode and decode` method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
This project is kindly sponsored by nearForm.
MIT