duplex
base class for a duplex stream
Last updated 12 years ago .
Repository · Original npm · Tarball · package.json
$ npm install duplex 
SYNC missed versions from official npm registry.

duplex

Simple base class for duplex streams, that automatically handles pausing and buffering.


var duplex = require('duplex')

var d = duplex()
  .on('write', function (data) {
    d.sendData(data)
  })
  .on('ended', function () {
    d.sendEnd()
  })

API

on('write', function (data))

Emitted when write(data) is called.

on('ended', function ())

Emitted when end() is called

sendData(data)

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

sendEnd()

Emit 'end' after the output buffer drains.
Will be emitted immediately, it the buffer is empty.

pause()

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

resume()

Set the reabable side of the stream into the unpaused state.
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.

Automatic Behaviours

destroy() is called automitically after both sides of the stream has 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'.

The stream will call resume() in the next tick, unless pause() is called manually. if resume() is manually called before the next tick, the stream will start emitting data immediately.

License

MIT / APACHE 2

Current Tags

  • 1.0.0                                ...           latest (12 years ago)

10 Versions

  • 1.0.0                                ...           12 years ago
  • 0.2.4                                ...           12 years ago
  • 0.2.2                                ...           12 years ago
  • 0.2.1                                ...           12 years ago
  • 0.1.4                                ...           12 years ago
  • 0.1.3                                ...           12 years ago
  • 0.1.2                                ...           12 years ago
  • 0.1.1                                ...           12 years ago
  • 0.1.0                                ...           12 years ago
  • 0.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Total 11
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE