net-buffer
Very fast message length-prefixing encoder and decoder.
.encode([Buffer])
encode can accept Buffer
or undefined
var net= var netBuf= var client= net
.decode(socket, callback[, bodyOnly])
decode directly reads from the socekt without using the socket.on('data', ) event.
var net= var decode= decode net
- socket Socket
- callback Function, called with a single Buffer argument
- bodyOnly Boolean, Optional, Default true; Set to false to get body prefixed with length (can reuse Buffer when need to proxy the Buffer)
.setMaxMessageLength(number)
Defines the maximum supported message length (header), valid values are 2 (for 65,135 bytes) and 4 (for 4,294,967,196 bytes), default is 2.
var netBuf= netBuf
Benchmark
Below is Mac Air 2013 results
$ node test.js 100000 $ > ok sent and received 100000 messages in 0.786218543 seconds
Installation
npm install net-buffer
MIT License