New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

event2stream

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event2stream

A module that transforms an EventEmitter into a ReadableStream

latest
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

Travis CI

event2stream

Overview

A module that transforms an EventEmitter into a ReadableStream. Internally to the module this is accomplished by keeping a buffer in memory. Future releases will include the ability to use other forms of buffering.

The module was created to satify an easy way to test other modules that consume readable streams. Rather than requiring the use of fs.createReadStream or similar, this module allows for any a custom readable stream to be implemented easily.

Examples

Example: Convert log events into a stream and connect the stream to stdout.

const events = require( "events" );
const event2stream = require( "event2stream" );

const myEventEmitter = new events.EventEmitter( );
const eventStream = new event2stream( {
	eventEmitter: myEventEmitter,
	eventNames: [ "log" ]
} );

eventStream.pipe( process.stdout );

myEventEmitter.emit( "log", "This is a log message." );
myEventEmitter.emit( "log", "Another log message" );

setTimeout( function( ){
	eventStream.die();
}, 1500 );

Example: Sample event to stream conversion using an object stream. Demonstrates the pause() and resume() functionality.

const events = require( "events" );
const event2stream = require( "event2stream" );

const myEventEmitter = new events.EventEmitter( );
const eventStream = new event2stream( {
	eventEmitter: myEventEmitter,
	eventNames: [ "hey" ],
	mode: "object"
} );

eventStream.pause( );

eventStream.on( "data", function( data ){
	console.log( data ); // { "eventName": "hey", "data": { "This": "is", data: 1 }

	eventStream.die( );
} );

myEventEmitter.emit( "hey", { "This": "is", data: 1 } );

setTimeout( function( ){
	eventStream.resume();
}, 1000 );

FAQs

Package last updated on 21 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts