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

streamize

v0.0.1

Published

stream helper for NodeJs

Downloads

6

Readme

streamize

stream helper for NodeJs

NPM Version NPM Downloads Build Coverage Status NSP Status Dependencies Status

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 6 or higher is required.

Installation is done using the npm install command:

$ npm install streamize

Documentation

Readable

Description: create a readable stream

streamize.Readable(read, [options])

return a readable stream

sample

var streamize = require('streamize');
var myArray = ['1', '2', '3', '4', '5'];
// create a readable stream from myArray
var readable = streamize.Readable(function(cb) {
  cb(null, myArray.shift() || null);
});

the read function passed in argument is called each time a new chunk is required. the callback takes 2 arguments:

  • error

When error is defined and not null, the stream returned emit the error and chunk is ignored.

  • chunk

When chunk is a Buffer, Uint8Array or string, the chunk of data will be added to the internal queue for users of the stream to consume. Passing chunk as null signals the end of the stream (EOF), after which no more data can be written.

As read function is called in the stream context, every internal function could be called from this.

var readable = streamize.Readable(function(cb) {
  // push 'a' into the stream
  this.push('a');
  cb(null, myArray.shift() || null);
});

Writable

Description: create a writable stream

streamize.Writable(write, [options])

  • write is a function that take the chunk to be written and a callback function as arguments.
  • options is an optional object argument passed to the node stream: see node writable stream documentation

sample

var streamize = require('streamize');
var newArray = [];
// create a writable stream that push chunk in newArray
var writable = streamize.Writable(function(chunk, cb) {
  newArray.push(chunk);
  cb();
});

the write function is called each time a chunk should be written. chunk | | The chunk to be written. Will always be a buffer unless the decodeStrings option was set to false or the stream is operating in object mode. callback Call this function (optionally with an error argument) when processing is complete for the supplied chunk.

Duplex

Description: create a duplex stream

streamize.Duplex(read, write, [options])

sample

var streamize = require('streamize');
var myArray = ['1', '2', '3', '4', '5'];
var newArray = [];
// create a duplex stream that read myArray and write in newArray
var duplex = streamize.Duplex(function(cb) {
  cb(null, myArray.shift() || null);
}, function(data, cb) {
  newArray.push(chunk);
  cb();
});

Transform

Description: create a transform stream

streamize.Transform(transform, [options])

  • transform is a function that take the chunk to be transform and a callback function as arguments.
  • options is an optional object argument passed to the node stream: see node transform stream documentation

sample

var streamize = require('streamize');
// create a transform stream that duplicate all chunks
var transform = streamize.Transform(function(chunk, cb) {
  this.push(chunk);
  cb(null, chunk);
});

the transform function is called each time a chunk should be transform. chunk | | The chunk to be written. Will always be a buffer unless the decodeStrings option was set to false or the stream is operating in object mode. callback A callback function (optionally with an error argument and data) to be called after the supplied chunk has been processed.

As transform function is called in the stream context, every internal function could be called from this.

Object mode

streamize.obj.Readable(read, [options])

streamize.obj.Writable(write, [options])

streamize.obj.Duplex(read, write, [options])

streamize.obj.Transform(transform, [options])

do the same but return a stream in object mode.