https://github.com/rumkin/boundary-stream
Length prefixed stream encoder and decoder for network transport
https://github.com/rumkin/boundary-stream
boundary-stream javascript streams transport-protocols
Last synced: 3 months ago
JSON representation
Length prefixed stream encoder and decoder for network transport
- Host: GitHub
- URL: https://github.com/rumkin/boundary-stream
- Owner: rumkin
- License: mit
- Created: 2016-06-22T15:20:45.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-28T13:48:03.000Z (over 7 years ago)
- Last Synced: 2025-03-03T13:19:58.690Z (3 months ago)
- Topics: boundary-stream, javascript, streams, transport-protocols
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Boundary Stream
[](https://npmjs.com/packages/boundary-stream)
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:
```shell
npm i boundary-stream
```## Usage
Example of raw Buffer message transfer.
### Client
```javascript
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
```javascript
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