Socket
Socket
Sign inDemoInstall

measure-stream

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    measure-stream

Node streams that know their lengths.


Version published
Maintainers
1
Created

Changelog

Source

3.0.2 (2023-09-17)

Bug Fixes

  • Use 'node:' protocol in imports (#117) (0be1e7c)

Readme

Source

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
})

Keywords

FAQs

Last updated on 17 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc