# stream-events

> Get an event when you're being sent data or asked for it.

Latest version **1.0.5** (published 2018-10-26) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2018-10-26 |
| First published | 2014-10-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Stephen Sawchuk |
| Maintainers | stephenplusplus |
| Keywords | stream, events, read, write, duplexify, lazy-stream |

## Links

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

## Dependencies (1)

- [stubs](https://npm.io/package/stubs.md) ^3.0.0

## 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.5 (latest) — 2018-10-26
- 1.0.4 — 2018-04-13
- 1.0.3 — 2018-04-02
- 1.0.2 — 2017-05-08
- 1.0.1 — 2014-10-16
- 1.0.0 — 2014-10-16

## README

# stream-events

> Get an event when you're being sent data or asked for it.

## About

This is just a simple thing that tells you when `_read` and `_write` have been called, saving you the trouble of writing this yourself. You receive two events `reading` and `writing`-- no magic is performed.

This works well with [duplexify](https://github.com/mafintosh/duplexify) or lazy streams, so you can wait until you know you're being used as a stream to do something asynchronous, such as fetching an API token.


## Use
```sh
$ npm install --save stream-events
```
```js
var stream = require('stream')
var streamEvents = require('stream-events')
var util = require('util')

function MyStream() {
  stream.Duplex.call(this)
  streamEvents.call(this)
}
util.inherits(MyStream, stream.Duplex)

MyStream.prototype._read = function(chunk) {
  console.log('_read called as usual')
  this.push(new Buffer(chunk))
  this.push(null)
}

MyStream.prototype._write = function() {
  console.log('_write called as usual')
}

var stream = new MyStream

stream.on('reading', function() {
  console.log('stream is being asked for data')
})

stream.on('writing', function() {
  console.log('stream is being sent data')
})

stream.pipe(stream)
```

### Using with Duplexify
```js
var duplexify = require('duplexify')
var streamEvents = require('stream-events')
var fs = require('fs')

var dup = streamEvents(duplexify())

dup.on('writing', function() {
  // do something async
  dup.setWritable(/*writable stream*/)
})

fs.createReadStream('file').pipe(dup)
```

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