3.0.2 • Published 8 months ago

measure-stream v3.0.2

Weekly downloads
57
License
MIT
Repository
github
Last release
8 months ago

measure-stream

CI Test Coverage Maintainability

A duplex (Transform) stream for Node.js 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')

const 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 () {
  const bytes = stream.measurements.totalLength
})
3.0.2

8 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.0

6 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago