# end-of-stream

> Call a callback when a readable/writable/duplex stream has completed or failed.

Latest version **1.4.5** (published 2025-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install end-of-stream
pnpm add end-of-stream
yarn add end-of-stream
bun add end-of-stream
```

## Health

**Score 48/100 (D)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.4.5 |
| Published | 2025-06-16 |
| First published | 2013-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/end-of-stream) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 149 |
| Author | Mathias Buus |
| Maintainers | mafintosh |
| Keywords | stream, streams, callback, finish, close, end, wait |

## Links

- npm: https://www.npmjs.com/package/end-of-stream
- Repository: https://github.com/mafintosh/end-of-stream
- Issues: https://github.com/mafintosh/end-of-stream/issues
- npm.io page: https://npm.io/package/end-of-stream

## Dependencies (1)

- [once](https://npm.io/package/once.md) ^1.4.0

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 1.4.5 (latest) — 2025-06-16
- 1.4.4 — 2019-09-25
- 1.4.3 — 2019-09-24
- 1.4.2 — 2019-09-23
- 1.4.1 — 2018-01-10
- 1.4.0 — 2017-03-14
- 1.3.0 — 2017-03-14
- 1.2.0 — 2017-03-10
- 1.1.0 — 2014-09-07
- 1.0.0 — 2014-07-21
- 0.1.5 — 2014-06-29
- 0.1.4 — 2014-02-18
- 0.1.3 — 2013-12-19
- 0.1.2 — 2013-11-27
- 0.1.1 — 2013-11-27
- … 1 more at https://npm.io/package/end-of-stream/versions

## README

# end-of-stream

A node module that calls a callback when a readable/writable/duplex stream has completed or failed.

	npm install end-of-stream

[![Build status](https://travis-ci.org/mafintosh/end-of-stream.svg?branch=master)](https://travis-ci.org/mafintosh/end-of-stream)

## Usage

Simply pass a stream and a callback to the `eos`.
Both legacy streams, streams2 and stream3 are supported.

``` js
var eos = require('end-of-stream');

eos(readableStream, function(err) {
  // this will be set to the stream instance
	if (err) return console.log('stream had an error or closed early');
	console.log('stream has ended', this === readableStream);
});

eos(writableStream, function(err) {
	if (err) return console.log('stream had an error or closed early');
	console.log('stream has finished', this === writableStream);
});

eos(duplexStream, function(err) {
	if (err) return console.log('stream had an error or closed early');
	console.log('stream has ended and finished', this === duplexStream);
});

eos(duplexStream, {readable:false}, function(err) {
	if (err) return console.log('stream had an error or closed early');
	console.log('stream has finished but might still be readable');
});

eos(duplexStream, {writable:false}, function(err) {
	if (err) return console.log('stream had an error or closed early');
	console.log('stream has ended but might still be writable');
});

eos(readableStream, {error:false}, function(err) {
	// do not treat emit('error', err) as a end-of-stream
});
```

## License

MIT

## Related

`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.

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