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

stream-meter

v1.0.4

Published

A stream meter that both counts the bytes piped through it, and can optionally abort on a max size. (e.g. limit a http request size)

Downloads

1,023,123

Readme

Stream Meter

NPM

david-dm david-dm

Stream Meter is a... uh, meter for streams.

It is a streams2 Transform stream that passes through content, but counts the number of bytes it forwards.

However, give it a size in bytes and it will abort as soon as that threshold is passed. This is useful for capping your hyperquest or http/https clients or servers content size.

npm install stream-meter

Examples:

var meter = require("stream-meter")

// make an un-capped meter
var m = meter()
process.stdin.pipe(m).pipe(process.stdout)
setTimeout(function () {
  // Log how much we saw in a couple seconds.
  console.log(m.bytes)
}, 2000)

// this will abort (with an Error) in the frame where 1024 bytes is reached
process.stdin.pipe(meter(1024)).pipe(process.stdout)

// create a 1024 byte-capped meter
var m = meter(1024)
m.on("error", function (e) {
  // log the error but don't kill the process
  console.log(e.message)
})
process.stdin.pipe(m).pipe(process.stdout)
var hyperquest = require("hyperquest")

var req = hyperquest("https://raw.github.com/mranney/node_redis/master/index.js")

var meter = require("stream-meter")(1024)
meter.on("error", function (e) {
  console.log(e.message)
  console.log("Read %s bytes", meter.bytes)
})


req.pipe(meter).pipe(process.stderr)
$ node hypermeter.js 2> /dev/null
Stream exceeded specified max of 1024 bytes.
Read 7377 bytes

Usage

var meter = require("stream-meter")

var stream = meter(size)
stream.on("error", function (e) {
  // handle the meter aborting the stream
})

// read the bytes processed by the meter and passed through to any subsequent streams.
var size = stream.bytes

See test/index.js for additional examples.

Options

size

Size (in bytes) to trigger the stream to abort. It will complete whatever frame it aborted in, so the size streamed will still be >= size but no more than size + highWaterMark

Properties

bytes

Number of bytes handled and passed through the meter.

LICENSE

MIT