0.2.0 • Published 5 years ago

jemit v0.2.0

Weekly downloads
2
License
LGPL-3.0
Repository
github
Last release
5 years ago

jemit

A user friendly JSON stream module with event support.

Travis npm npm

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:

keydefaultdescription
delimiter'\n'delemiter to split stream (no need to change)
maxParseBufferSize32768max size for the parsing buffer
writableHighWaterMarkNodeJS defaultNodeJS Doc
readableHighWaterMarkNodeJS defaultNodeJS Doc

jemit.OutputStream

The stream is a NodeJS Transform Stream. For the methods see: NodeJS Steam API

new jemit.OutputStream(options)

options:

keydefaultdescription
delimiter'\n'delemiter to split stream (no need to change)
maxChunkSize16384max chunk size for internal writing (push)
writableHighWaterMarkNodeJS defaultNodeJS Doc
readableHighWaterMarkNodeJS defaultNodeJS Doc