1.0.0 • Published 9 years ago

denial-stream v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

denial-stream

Prevent unpiping on error in stream

build status

Example

var denialStream = require('denial-stream')
var from = require('from2')
var through = require('through2')

var dataStream = from.obj([1, 2, 3, 4, 5, 6, 7])

var failStream = through.obj(function(chunk, enc, callback) {
  if (chunk % 2) return callback(new Error('not cool'))
  this.push(chunk + '')
  callback()
})

// Errors are still emitted from original stream
failStream.on('error', function (err) {
  console.log(err)
})

dataStream
  // No error events will be emitted from denialStream
  .pipe(denialStream(failStream))
  .pipe(process.stdout)

Usage

var d = denialStream(stream)

Wraps a readable/writable stream in a new stream

Events

d.on('deniedError', function (err) {})

The deniedError event is emitted when the passed in stream emits an error. deniedStream suppresses normal error events to prevent the stream from unpiping and instead forwards errors with the deniedError event.

License

MIT