# duplex

> base class for a duplex stream

Latest version **1.0.0** (published 2012-11-13) · 0 weekly downloads

## Install

```sh
npm install duplex
pnpm add duplex
yarn add duplex
bun add duplex
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2012-11-13 |
| First published | 2012-07-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18 |
| Author | Dominic Tarr |
| Maintainers | dominictarr |

## Links

- npm: https://www.npmjs.com/package/duplex
- Repository: https://github.com/dominictarr/duplex
- npm.io page: https://npm.io/package/duplex

## Recent versions

- 1.0.0 (latest) — 2012-11-13
- 0.2.4 — 2012-10-21
- 0.2.2 — 2012-10-11
- 0.2.1 — 2012-09-26
- 0.2.0 — 2012-09-26
- 0.1.4 — 2012-09-11
- 0.1.3 — 2012-09-11
- 0.1.2 — 2012-08-14
- 0.1.1 — 2012-08-11
- 0.1.0 — 2012-07-25
- 0.0.1 — 2012-07-25

## README

# duplex

<img src=https://secure.travis-ci.org/dominictarr/duplex.png?branch=master>


Simple base class for [duplex](https://github.com/dominictarr/stream-spec#duplex) streams, that automatically handles pausing and buffering.

``` js

var duplex = require('duplex')

var d = duplex()
  .on('_data', function (data) {
    d.sendData(data)
  })
  .on('_end', function () {
    d.sendEnd()
  })
```

## API

### on('_data', function (data))

Emitted when `write(data)` is called.

### on('_end', function ())

Emitted when `end()` is called

### _data(data)

Add `data` to the output buffer. 
`'data'` will be emitted if the stream is not paused.

### _end()

Cap the output buffer. no more data events may be added.
`'end'` will be emitted after the buffer drains, 
or immediately, if the stream is unpaused.

### pause()

Pause the readable side of the stream.  
This will prevent it from emitting 'data' or or 'end'
until resume is called.

### resume()
Unpause the readable side of the stream.  
This will allow it to emit `'data'` and `'end'` events.  
If there there is any data in the output buffer,  
It will start draining immediately.  

## _pause(), emit('pause')

Pause the writable side of the stream. this will cause write() to return false,
so any streams piping into this stream will pause after thier next write.

## emit('drain')

Unpause the writable side of the stream. This will cause `Stream#pipe` to call `resume()`
on any streams piping to this stream.

## Automatic Behaviours

`destroy()` is called automatically after both sides of the stream have ended.
`write()==false` after the stream emits `'pause'`,  
and `write()==true` after the stream emits `'drain'`.
The user is responsible for emitting `'pause'` and `'drain'`.

`resume()` will be called on `nextTick`, unless `pause()` was called manually.
If `resume()` is manually called before the `nextTick`, the stream will start emitting data
immediately.

## License

MIT / APACHE 2

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