Comparing version 2.6.0 to 2.6.1
37
index.js
@@ -6,2 +6,3 @@ 'use strict' | ||
const MAYBE_EMIT_END = Symbol('maybeEmitEnd') | ||
const REMOVE_ALL_END_LISTENERS = Symbol('removeAllEndListeners') | ||
const EMITTED_END = Symbol('emittedEnd') | ||
@@ -35,2 +36,10 @@ const EMITTING_END = Symbol('emittingEnd') | ||
// events that mean 'the stream is over' | ||
// these are treated specially, and re-emitted | ||
// if they are listened for after emitting. | ||
const isEndish = ev => | ||
ev === 'end' || | ||
ev === 'finish' || | ||
ev === 'prefinish' | ||
module.exports = class MiniPass extends EE { | ||
@@ -168,4 +177,8 @@ constructor (options) { | ||
this.writable = false | ||
if (this.flowing) | ||
this[MAYBE_EMIT_END]() | ||
// if we haven't written anything, then go ahead and emit, | ||
// even if we're not reading. | ||
// we'll re-emit if a new 'end' listener is added anyway. | ||
// This makes MP more suitable to write-only use cases. | ||
this[MAYBE_EMIT_END]() | ||
return this | ||
@@ -248,5 +261,5 @@ } | ||
this[RESUME]() | ||
else if (ev === 'end' && this[EMITTED_END]) { | ||
super.emit('end') | ||
this.removeAllListeners('end') | ||
else if (isEndish(ev) && this[EMITTED_END]) { | ||
super.emit(ev) | ||
this[REMOVE_ALL_END_LISTENERS]() | ||
} | ||
@@ -265,3 +278,2 @@ } | ||
this[EOF]) { | ||
this[EMITTING_END] = true | ||
@@ -273,2 +285,4 @@ this.emit('end') | ||
this.emit('close') | ||
this[REMOVE_ALL_END_LISTENERS]() | ||
this[EMITTING_END] = false | ||
} | ||
@@ -285,2 +299,3 @@ } | ||
} else if (ev === 'end') { | ||
// only actual end gets this treatment | ||
if (this[EMITTED_END] === true) | ||
@@ -324,9 +339,15 @@ return | ||
} finally { | ||
if (ev !== 'end') | ||
if (!isEndish(ev)) | ||
this[MAYBE_EMIT_END]() | ||
else | ||
this.removeAllListeners('end') | ||
this[REMOVE_ALL_END_LISTENERS]() | ||
} | ||
} | ||
[REMOVE_ALL_END_LISTENERS] () { | ||
this.removeAllListeners('end') | ||
this.removeAllListeners('prefinish') | ||
this.removeAllListeners('finish') | ||
} | ||
// const all = await stream.collect() | ||
@@ -333,0 +354,0 @@ collect () { |
{ | ||
"name": "minipass", | ||
"version": "2.6.0", | ||
"version": "2.6.1", | ||
"description": "minimal implementation of a PassThrough stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18335
359