jemit
v0.2.0
Published
A JSON Object event stream for nodejs.
Downloads
2
Readme
jemit
A user friendly JSON stream module with event support.
Usage
Example
Using events
const jemit = require('jemit');
let input = new jemit.Input();
let output = new jemit.Output();
output.stream.pipe(input.stream);
input.on('error', (e) => {
console.error(e);
});
input.on('test', (data) => {
console.log('test1:', data);
});
output.emit('test', {i: 1});
output.end();
Using the streams
const jemit = require('jemit');
let inputStream = new jemit.InputStream();
let outputStream = new jemit.OutputStream();
outputStream.pipe(inputStream);
inputStream.on('error', (e) => {
console.error(e);
});
inputStream.on('data', (data) => {
console.log('data:', data);
});
outputStream.write({i: 1});
outputStream.end();
API
jemit.Input
the Input is a NodeJS EventEmitter
new jemit.Input([options])
options: see: InputStream
.stream
The jemit InputStream is accessible via .stream
Event: *
All events what will be received from the stream will be emitted.
Event: 'error'
The error event is emitted on every error with the stream. Errors will normally not stop the streaming, but you will lose affected data.
jemit.Output
new jemit.Output([options])
options: see: OutputStream
.emit(event, [object])
event: object:
This is not the original emit() method from the EventEmitter
.stream
The jemit OutputStream is accessible via .stream
Event: 'error'
The error event is emitted on every error with the stream. Errors will normally not stop the streaming, but you will lose affected data.
jemit.InputStream
The stream is a NodeJS Transform Stream. For the methods see: NodeJS Steam API
new jemit.InputStream([options])
options:
| key | default | description | | --------------------- | -------------- | ----------------------------------------------| | delimiter | '\n' | delemiter to split stream (no need to change) | | maxParseBufferSize | 32768 | max size for the parsing buffer | | writableHighWaterMark | NodeJS default | NodeJS Doc | | readableHighWaterMark | NodeJS default | NodeJS Doc |
jemit.OutputStream
The stream is a NodeJS Transform Stream. For the methods see: NodeJS Steam API
new jemit.OutputStream([options])
options:
| key | default | description | | --------------------- | -------------- | ----------------------------------------------| | delimiter | '\n' | delemiter to split stream (no need to change) | | maxChunkSize | 16384 | max chunk size for internal writing (push) | | writableHighWaterMark | NodeJS default | NodeJS Doc | | readableHighWaterMark | NodeJS default | NodeJS Doc |