Comparing version 2.8.1 to 2.8.2
44
index.js
@@ -18,2 +18,6 @@ 'use strict' | ||
const PAUSED = Symbol('paused') | ||
// enum for paused states. | ||
const PAUSE_FALSE = Symbol('pausedFalse') | ||
const PAUSE_IMPLICIT = Symbol('pausedImplicit') | ||
const PAUSE_EXPLICIT = Symbol('pausedExplicit') | ||
const RESUME = Symbol('resume') | ||
@@ -47,3 +51,3 @@ const BUFFERLENGTH = Symbol('bufferLength') | ||
module.exports = class Minipass extends EE { | ||
class Minipass extends EE { | ||
constructor (options) { | ||
@@ -53,3 +57,3 @@ super() | ||
// whether we're explicitly paused | ||
this[PAUSED] = false | ||
this[PAUSED] = PAUSE_FALSE | ||
this.pipes = new Yallist() | ||
@@ -207,3 +211,3 @@ this.buffer = new Yallist() | ||
// This makes MP more suitable to write-only use cases. | ||
if (this.flowing || !this[PAUSED]) | ||
if (this.flowing || this[PAUSED] !== PAUSE_EXPLICIT) | ||
this[MAYBE_EMIT_END]() | ||
@@ -218,3 +222,3 @@ return this | ||
this[PAUSED] = false | ||
this[PAUSED] = PAUSE_FALSE | ||
this[FLOWING] = true | ||
@@ -234,5 +238,10 @@ this.emit('resume') | ||
[PAUSE_IMPLICIT] () { | ||
this[FLOWING] = false | ||
this[PAUSED] = PAUSE_IMPLICIT | ||
} | ||
pause () { | ||
this[FLOWING] = false | ||
this[PAUSED] = true | ||
this[PAUSED] = PAUSE_EXPLICIT | ||
} | ||
@@ -249,3 +258,3 @@ | ||
get paused () { | ||
return this[PAUSED] | ||
return this[PAUSED] !== PAUSE_FALSE | ||
} | ||
@@ -293,7 +302,17 @@ | ||
const p = { dest: dest, opts: opts, ondrain: _ => this[RESUME]() } | ||
// ondrain only resumes in the PAUSE_IMPLICIT case, not PAUSE_EXPLICIT | ||
// don't bother calling resume if we're already flowing. | ||
const p = { | ||
dest: dest, | ||
opts: opts, | ||
ondrain: _ => this[PAUSED] === PAUSE_IMPLICIT && this[RESUME]() | ||
} | ||
this.pipes.push(p) | ||
dest.on('drain', p.ondrain) | ||
this[RESUME]() | ||
// don't start flowing if we're explicitly paused | ||
if (this[PAUSED] !== PAUSE_EXPLICIT) | ||
this[RESUME]() | ||
// piping an ended stream ends immediately | ||
@@ -313,3 +332,4 @@ if (ended && p.opts.end) | ||
} finally { | ||
if (ev === 'data' && !this.pipes.length && !this.flowing) | ||
if (ev === 'data' && !this.pipes.length && !this.flowing && | ||
this[PAUSED] !== PAUSE_EXPLICIT) | ||
this[RESUME]() | ||
@@ -357,3 +377,3 @@ else if (isEndish(ev) && this[EMITTED_END]) { | ||
this.pipes.forEach(p => | ||
p.dest.write(data) === false && this.pause()) | ||
p.dest.write(data) === false && this[PAUSE_IMPLICIT]()) | ||
} else if (ev === 'end') { | ||
@@ -457,3 +477,3 @@ // only actual end gets this treatment | ||
this.removeListener('end', onend) | ||
this.pause() | ||
this[PAUSE_IMPLICIT]() | ||
resolve({ value: value, done: !!this[EOF] }) | ||
@@ -523,1 +543,3 @@ } | ||
} | ||
module.exports = Minipass |
{ | ||
"name": "minipass", | ||
"version": "2.8.1", | ||
"version": "2.8.2", | ||
"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
30566
455