# stream-meter

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

Latest version **1.0.4** (published 2016-07-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-meter
pnpm add stream-meter
yarn add stream-meter
bun add stream-meter
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2016-07-13 |
| First published | 2013-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/stream-meter) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | Bryce B. Baril |
| Maintainers | bryce |
| Keywords | streams2, streams, meter, abort |

## Links

- npm: https://www.npmjs.com/package/stream-meter
- Repository: https://github.com/brycebaril/node-stream-meter
- Homepage: https://github.com/brycebaril/node-stream-meter#readme
- Issues: https://github.com/brycebaril/node-stream-meter/issues
- npm.io page: https://npm.io/package/stream-meter

## Dependencies (1)

- [readable-stream](https://npm.io/package/readable-stream.md) ^2.1.4

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2016-07-13
- 1.0.3 — 2013-09-25
- 1.0.2 — 2013-09-23
- 1.0.1 — 2013-07-21
- 1.0.0 — 2013-07-04

## README

Stream Meter
============

[![NPM](https://nodei.co/npm/stream-meter.png)](https://nodei.co/npm/stream-meter/)

[![david-dm](https://david-dm.org/brycebaril/node-stream-meter.png)](https://david-dm.org/brycebaril/node-stream-meter/)
[![david-dm](https://david-dm.org/brycebaril/node-stream-meter/dev-status.png)](https://david-dm.org/brycebaril/node-stream-meter#info=devDependencies/)

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](http://npm.im/hyperquest) or http/https clients or servers content size.

```
npm install stream-meter
```

Examples:

```javascript
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)

```

```javascript
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)
```

```bash
$ node hypermeter.js 2> /dev/null
Stream exceeded specified max of 1024 bytes.
Read 7377 bytes
```

Usage
=====

```javascript
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

---
_Source: https://npm.io/package/stream-meter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
