Skip to content

Handles completion and errors of any stream - readable/writable/duplex. A drop-in replacement for end-of-stream.

License

Notifications You must be signed in to change notification settings

tunnckoCore/on-stream-end

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handles completion and errors of any stream - readable/writable/duplex.
A drop-in replacement for end-of-stream.

code climate standard code style travis build status coverage status dependency status

Install

npm i on-stream-end --save

Usage

For more use-cases see the tests

const eos = require('on-stream-end')

Handles completion and errors of any stream - readable/writable/duplex.

  • stream {Stream} stream to listen for completion
  • opts {Object} optional options object
  • callback {Function} completion callback

Example

const fs = require('fs')
const eos = require('on-stream-end')
const readable = fs.createReadStream('README.md')

eos(readable, err => {
  if (err) return console.log('stream had an error or closed early')
  console.log('stream has ended')
})

More examples

This module is drop-in replacement for end-of-stream, just more strictness, more coverage and more tests.

var eos = require('on-stream-end')

eos(readableStream, function (err) {
  if (err) return console.log('stream had an error or closed early')
  console.log('stream has ended')
})

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

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

eos(duplexStream, {readable: 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(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 readable')
})

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

Related

  • catchup: Graceful error handling. Because core domain module is deprecated.
  • end-of-stream: Call a callback when a readable/writable/duplex stream has completed or failed.
  • is-node-emitter: Strictly checks that given value is nodejs EventEmitter.
  • is-node-stream: Strictly and correctly checks if value is a nodejs stream.

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Handles completion and errors of any stream - readable/writable/duplex. A drop-in replacement for end-of-stream.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published