diff options
Diffstat (limited to 'deps/npm/node_modules/minipass/index.js')
-rw-r--r-- | deps/npm/node_modules/minipass/index.js | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/deps/npm/node_modules/minipass/index.js b/deps/npm/node_modules/minipass/index.js index 5d45de8d39..97b23068c9 100644 --- a/deps/npm/node_modules/minipass/index.js +++ b/deps/npm/node_modules/minipass/index.js @@ -8,7 +8,8 @@ const proc = } const EE = require('events') const Stream = require('stream') -const SD = require('string_decoder').StringDecoder +const stringdecoder = require('string_decoder') +const SD = stringdecoder.StringDecoder const EOF = Symbol('EOF') const MAYBE_EMIT_END = Symbol('maybeEmitEnd') @@ -38,6 +39,9 @@ const EMITDATA = Symbol('emitData') const EMITEND = Symbol('emitEnd') const EMITEND2 = Symbol('emitEnd2') const ASYNC = Symbol('async') +const ABORT = Symbol('abort') +const ABORTED = Symbol('aborted') +const SIGNAL = Symbol('signal') const defer = fn => Promise.resolve().then(fn) @@ -93,7 +97,7 @@ class PipeProxyErrors extends Pipe { } } -module.exports = class Minipass extends Stream { +class Minipass extends Stream { constructor(options) { super() this[FLOWING] = false @@ -122,6 +126,14 @@ module.exports = class Minipass extends Stream { if (options && options.debugExposePipes === true) { Object.defineProperty(this, 'pipes', { get: () => this[PIPES] }) } + this[SIGNAL] = options && options.signal + this[ABORTED] = false + if (this[SIGNAL]) { + this[SIGNAL].addEventListener('abort', () => this[ABORT]()) + if (this[SIGNAL].aborted) { + this[ABORT]() + } + } } get bufferLength() { @@ -168,7 +180,20 @@ module.exports = class Minipass extends Stream { this[ASYNC] = this[ASYNC] || !!a } + // drop everything and get out of the flow completely + [ABORT]() { + this[ABORTED] = true + this.emit('abort', this[SIGNAL].reason) + this.destroy(this[SIGNAL].reason) + } + + get aborted() { + return this[ABORTED] + } + set aborted(_) {} + write(chunk, encoding, cb) { + if (this[ABORTED]) return false if (this[EOF]) throw new Error('write after end') if (this[DESTROYED]) { @@ -342,21 +367,20 @@ module.exports = class Minipass extends Stream { } [BUFFERSHIFT]() { - if (this[BUFFER].length) { - if (this[OBJECTMODE]) this[BUFFERLENGTH] -= 1 - else this[BUFFERLENGTH] -= this[BUFFER][0].length - } + if (this[OBJECTMODE]) this[BUFFERLENGTH] -= 1 + else this[BUFFERLENGTH] -= this[BUFFER][0].length return this[BUFFER].shift() } [FLUSH](noDrain) { - do {} while (this[FLUSHCHUNK](this[BUFFERSHIFT]())) + do {} while (this[FLUSHCHUNK](this[BUFFERSHIFT]()) && this[BUFFER].length) if (!noDrain && !this[BUFFER].length && !this[EOF]) this.emit('drain') } [FLUSHCHUNK](chunk) { - return chunk ? (this.emit('data', chunk), this.flowing) : false + this.emit('data', chunk) + return this.flowing } pipe(dest, opts) { @@ -437,7 +461,7 @@ module.exports = class Minipass extends Stream { if (ev !== 'error' && ev !== 'close' && ev !== DESTROYED && this[DESTROYED]) return else if (ev === 'data') { - return !data + return !this[OBJECTMODE] && !data ? false : this[ASYNC] ? defer(() => this[EMITDATA](data)) @@ -454,7 +478,10 @@ module.exports = class Minipass extends Stream { } else if (ev === 'error') { this[EMITTED_ERROR] = data super.emit(ERROR, data) - const ret = super.emit('error', data) + const ret = + !this[SIGNAL] || this.listeners('error').length + ? super.emit('error', data) + : false this[MAYBE_EMIT_END]() return ret } else if (ev === 'resume') { @@ -659,8 +686,12 @@ module.exports = class Minipass extends Stream { (s instanceof Minipass || s instanceof Stream || (s instanceof EE && - (typeof s.pipe === 'function' || // readable - (typeof s.write === 'function' && typeof s.end === 'function')))) // writable + // readable + (typeof s.pipe === 'function' || + // writable + (typeof s.write === 'function' && typeof s.end === 'function')))) ) } } + +module.exports = Minipass |