Git Product home page Git Product logo

jemit's Introduction

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:

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

jemit's People

Contributors

killmag10 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.