JSPM

stream-end

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7
  • Score
    100M100P100Q39702F

I just want a callback when the stream ends

Package Exports

  • stream-end

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stream-end) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

stream-end NPM version Build Status

Just a callback when the stream ends. Called if the upstream is flowing with 'data' events or using Streams2 style reads.

Usage

I needed this for use with gulp, but it works with any stream.

gulp.src('specs/*.spec.coffee', {read: false})
  .pipe(mocha())
  .pipe(end(function() {
    return devServer.close();
  }));

Why!?

Can't we just use stream.on('end', cb)?

I wish. Unfortunately, streams are messy. There are at least 3 api conventions in node.

With some combinations of stream versions, the readable stream returned by pipe isn't flowing unless you manually resume() it. If you just register an 'end' listener, it may never be called. If the retured stream is flowing, your 'end' listner get's called just fine. It's a brittle habit.