# measure-stream

> Node streams that know their lengths.

Latest version **3.0.2** (published 2023-09-17) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2023-09-17 |
| First published | 2016-12-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.16.1 |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (Unknown) |
| GitHub stars | 0 |
| Author | Fabian Meyer |
| Maintainers | meyfa |
| Keywords | stream, streams, measure, through |

## Links

- npm: https://www.npmjs.com/package/measure-stream
- Repository: https://github.com/meyfa/measure-stream
- Issues: https://github.com/meyfa/measure-stream/issues
- npm.io page: https://npm.io/package/measure-stream

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

- 3.0.2 (latest) — 2023-09-17
- 3.0.1 — 2023-07-23
- 3.0.0 — 2023-07-05
- 2.2.0 — 2022-06-19
- 2.1.1 — 2022-02-11
- 2.1.0 — 2020-03-28
- 2.0.0 — 2019-11-17
- 1.0.0 — 2018-04-23
- 0.1.2 — 2017-07-26
- 0.1.1 — 2016-12-20
- 0.1.0 — 2016-12-20

## README

# measure-stream

[![CI](https://github.com/meyfa/measure-stream/actions/workflows/main.yml/badge.svg)](https://github.com/meyfa/measure-stream/actions/workflows/main.yml)
[![Test Coverage](https://api.codeclimate.com/v1/badges/8a458e83d62bf8a2c619/test_coverage)](https://codeclimate.com/github/meyfa/measure-stream/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/8a458e83d62bf8a2c619/maintainability)](https://codeclimate.com/github/meyfa/measure-stream/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

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

```javascript
stream.on('finish', function () {
  const bytes = stream.measurements.totalLength
})
```

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