Boundary stream converts passed data into length prefixed buffers. It helps to send data via tcp connection. Length prefixed protocols are more speed efficient then delimiter based (like HTTP).
Boundary stream can handle any size of message. The only limit is RAM size. It supports String or Buffer transfer and fits for JSON, MsgPack, CBOR and BORN encoders.
Install via npm:
npm i boundary-stream
Example of raw Buffer message transfer.
const net = require('net');
const boundary = require('boundary-stream');
const conn = net.connect(9090);
conn.on('connect', () => {
const writer = boundary.writer();
writer.pipe(conn);
writer.write(Buffer.alloc(10 * 1024 * 1024)); // Send 10 MiB buffer
writer.end();
});
// ...
const net = require('net');
const boundary = require('boundary-stream');
const server = net.createServer(function(conn){
let reader = boundary.reader();
reader.on('data', (message) => {
console.log(message.length); // -> 10485760
});
conn.pipe(reader);
});
// ...
Create Writer instance.
Create Reader instance.
Writer constructor
Write message to stream.
Reader constructor
MIT