net-object-stream
Turn any binary stream into an object stream, with multiple codec support
Example
'use strict' var net = var nos = var through2 = var pump = var server = net server
netObjectStream(stream, [opts])
Wraps stream
into a Duplex object stream, recognized opts:
codec
: an object with aencode
anddecode
method, which will be used to encode messages. Valid encoding libraries are protocol-buffers and msgpack5. The default one is JSON.
netObjectStream.encoder([opts])
Creates an encoder for the netObjectStream
protocol, recognized opts:
codec
: an object with aencode
anddecode
method, which will be used to encode messages. Valid encoding libraries are protocol-buffers and msgpack5. The default one is JSON.
netObjectStream.decoder([opts])
Creates a decoder for the netObjectStream
protocol, recognized opts:
codec
: an object with aencode
anddecode
method, which will be used to encode messages. Valid encoding libraries are protocol-buffers and msgpack5. The default one is JSON.
netObjectStream.parser([opts])
Creates a parser for the netObjectStream
protocol, recognized opts:
codec
: an object with aencode
anddecode
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.
It will emit 'message'
events when it is able to parse an object.
netObjectStream.writeToStream(msg, [opts], stream, [callback])
Write msg
to the given stream
, recognized options:
codec
: an object with aencode
anddecode
method, which will be used to encode messages. Valid encoding libraries are protocol-buffers and msgpack5. The default one is JSON.
Acknowledgements
This project is kindly sponsored by nearForm.
License
MIT