npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stream-lib

v0.1.0

Published

A library with stream utilities for node.js

Downloads

3

Readme

node-stream-lib

A library with stream utilities for node.js

How to install

npm install -s stream-lib

How to use

In general

var streamLib = require('stream-lib');

// your streamlib module like:
// new streamLib.Random.Alphanumeric();

Please take also a look into the JSDoc

Buffer

Buffers a stream in memory with a duplex stream. You are able to save the content in memory if the destination works slower then the source. You are able to close the destination earlier.

You can also use it in object mode, when you set the first paramerter to true;

var streamLib = require('stream-lib');

// You need some source and destination streams
var fs = require('fs');

var sourceStream = fs.createReadStream('/path/to/your/source.file');
var destinationStream = fs.createWriteStream('/path/to/your/destination.file');

// You need the buffer stream
var objectMode = false;                    // This is optional
var bufferStream = new streamLib.Buffer({objectMode: objectMode});

sourceStream.pipe(decoderStream)
    .pipe(destinationStream);

Concat

Concat multiple streams in given order.

var streamLib = require('stream-lib');

// You need some source and destination streams
var fs = require('fs');

var firstStream = fs.createReadStream('/path/to/your/first.file');
var secondStream = fs.createReadStream('/path/to/your/second.file');
var thirdStream = fs.createReadStream('/path/to/your/third.file');
var destinationStream = fs.createWriteStream('/path/to/your/destination.file');

// You need the concat stream
var concatStream = new streamLib.Concat();

firstStream
    .pipe(concatStream);
secondStream
    .pipe(concatStream);
thirdStream
    .pipe(concatStream);

concatStream.pipe(destinationStream);

Delay

Delay the flow of a stream.

There are a lot of other pipes. Please take a look in API-doc

var streamLib = require('stream-lib');

// You need some source and destination streams
var fs = require('fs');

var sourceStream = fs.createReadStream('/path/to/your/source.file');
var destinationStream = fs.createWriteStream('/path/to/your/destination.file');

// You need the buffer stream
var delay = 500;                                  // Delay in milli-seconds (Zero makes it just asynchronous)
var objectMode = false;                           // This is optional
var delayStream = new streamLib.Pipe.Delay({objectMode: objectMode});

sourceStream.pipe(delayStream)
    .pipe(destinationStream);

Event

An event stream works like a normal event emitter but works with streams.

You are also able to augment an existing event emitter with the eventStream.

var streamLib = require('stream-lib');

// Create an event stream

var eventStream = new streamLib.Event();


// For sending and getting Events
eventStream.receive('test', function (data) {
    console.log('Test received:', data);
});

eventStream.send('test', 'Hello!');


var EventEmitter = require('events').EventEmitter;

// anotherEventStream

var anotherEventStream = new streamLib.Event();

anotherEventStream.receive('test', function () {});

eventStr.pipe(anotherEventStream);

Unit

Create a unit of different pipes.

var streamLib = require('stream-lib');

// Create an unit

var unit = new streamLib.Unit();

// Create streams for the unit

var hexDecoder = new streamLib.HexEncoder();
var toUpperCaseStream = new streamLib.UpperCase();

// Combine to an unit

HexEncoder
    .pipe(toUpperCaseStream);

unit.setWritableStream(HexEncoder);
unit.setReadableStream(toUpperCaseStream);

// Now the unit create an upper case hex string

Sequence

Streams a never ending recorded sequence.

var streamLib = require('stream-lib');

// Create an sequence

var sequence = new streamLib.Sequence();

sequence.write('1');
sequence.write('2');
sequence.write('4');
sequence.write('8');
sequence.write('16');
sequence.end();

sequence.on('data', function (chunk) {
    console.log(chunk.toString());
});

// Outputs 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 1 2 4 8 16 ...

Measure

Makes measures on a stream

var streamLib = require('stream-lib');

// Create a measure

var measure = new streamLib.Measure.Capacity();

// Create some asynchronous pipes

var firstPipe = new streamLib.Pipe.Async();
var secondPipe = new streamLib.Pipe.Async();
var thirdPipe = new streamLib.Pipe.Async();

measure.measureInlet
    .pipe(firstPipe)
    .pipe(secondPipe)
    .pipe(thirdPipe)
    .pipe(measure.measureOutlet);

measure.measureInlet.write('1');
measure.measureInlet.write('2');
measure.measureInlet.write('3');
measure.measureInlet.write('4');
measure.measureInlet.write('5');
measure.measureInlet.end();

measure.on('data', function (chunk) {
    console.log(chunk.capacity);       // Now you got the measured capacity of the streams
});