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

node-streamer

v0.1.3

Published

Node.js streaming helper for async tasks

Downloads

9

Readme

Streamer

Build Status NPM

Streamer is a lib helping to iterate over streamed data while performing async operations on each piece of data streamed.

Install

npm install node-streamer

Usage

each

streamer.each(stream, iterator, callback)

Where :

  • stream is a node.js readable stream
  • iterator(elem, getStats, cb) is the method that will perform an async task. It has the following arguments:
    • elem data from the stream
    • getStats a method that can be called to get stats of the state of the current streaming, of the form:
      	{
      	  retrieved: <number>,
      	  processed: <number>
         }
    • cb to be called when the async task is done
  • callback the callback called when the stream is done

Example:

var streamer = require('node-streamer');

// Dummy method to get a readable stream
// Typically: a large file, a mysql or mongo stream, whatever really
var stream = getStream();

// For each `data` retrieved for the stream, execute the iterator method, do something async,
// then call the callback
streamer.each(stream, function (elem, getStats, cb) {
	myAsyncMethod(function (err) {
		var stats = getStats();
		console.log('%d/%d', stats.processed, stats.retrieved);
		return cb(err);
	})
}, function (err, stats) {
	console.log('DONE: %d/%d', stats.processed, stats.retrieved);
	// do something when done
});

Test

In order to test you'll need to install mocha: npm install -g mocha. Then just run the mocha command at the root of your project.

Contribute

This lib is still very basic and might not perfectly fit your needs. If you think it would make sense to add some features/methods don't hesitate to fork and make pull requests.

Licence

Distributed under the MIT License.