From 11ec2a76931cb6a9d9ebf541ed100d501ce54eb6 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Mon, 17 Aug 2015 14:36:48 -0400 Subject: [PATCH] dont emit closing events --- index.js | 10 +++++++++- test.js | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 96aa77e..7590413 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,15 @@ module.exports = function (stream, opts) { var eventNamesToEmit = toMap(opts.events || []); var catchAll = Object.keys(eventNamesToEmit).length === 0; - var eventNamesToExclude = toMap(opts.excludeEvents || []); + var endEvents = [ + 'abort', + 'close', + 'destroy', + 'end', + 'finish', + 'prefinish' + ]; + var eventNamesToExclude = toMap(opts.excludeEvents || endEvents); watchPipe(stream); diff --git a/test.js b/test.js index e22bbf0..0c82463 100644 --- a/test.js +++ b/test.js @@ -14,6 +14,23 @@ describe('stream-forward', function () { assert.strictEqual(sourceStream, returnedStream); }); + it('does not try to finish a piped stream', function () { + var streamThatErrors = through(); + + streamForward(streamThatErrors) + .pipe(through(function(chunk, enc, next) { + // let this back up so that if the source stream emits 'finish', and + // streamforward tries to re-emit that event on this stream, it will + // throw. + })); + + streamThatErrors.write('blah'); + + assert.doesNotThrow(function() { + streamThatErrors.emit('prefinish'); + }); + }); + it('forwards all events by default', function (done) { var eventsEmitted = 0;