boundary-stream

1.1.1 • Public • Published

Boundary Stream

npm

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

Install via npm:

npm i boundary-stream

Usage

Example of raw Buffer message transfer.

Client

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();
});
 
// ...

Server

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);
});
 
// ...

API

writer() -> Writer{}

Create Writer instance.

reader() -> Reader{}

Create Reader instance.

Writer()

Writer constructor

Writer().write(String|Buffer)

Write message to stream.

Reader()

Reader constructor

License

MIT

Package Sidebar

Install

npm i boundary-stream

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

12.7 kB

Total Files

10

Last publish

Collaborators

  • rumkin