npm

Need private packages and team management tools?Check out npm Orgs. »

measure-stream

2.0.0 • Public • Published

measure-stream

Build Status Test Coverage Maintainability

A duplex (Transform) stream for Node that measures the data passing through it and emits that info accordingly. The following properties are available:

  • chunks - The number of processed chunks up until and including the one that triggered the event.
  • totalLength - The sum of all chunk lengths. Will be 0 if the chunks are something other than strings or buffers.

Install

npm i measure-stream

Usage

const MeasureStream = require("measure-stream");
 
let stream = new MeasureStream();
stream.on("measure", function (info) {
    console.log("chunk count:", info.chunks);
    console.log("total length:", info.totalLength);
});
 
// You can then use 'stream' as you normally would, e.g.
// ('source' is readable and 'target' is writable):
source.pipe(stream).pipe(target);

As you can see, just one additional .pipe() call required to make it work!

Additionally, the last measurement is always available as a stream property. For example, if all you need is the total size after a stream has been processed:

stream.on("finish", function () {
    let bytes = stream.measurements.totalLength;
});

install

npm i measure-stream

Downloadsweekly downloads

52

version

2.0.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability