0.1.0 • Published 10 years ago

stream-end v0.1.0

Weekly downloads
12
License
-
Repository
github
Last release
10 years ago

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.