Skip to content

Commit

Permalink
deps: minipass@4.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Mar 8, 2023
1 parent e455e3f commit 1f60a7e
Show file tree
Hide file tree
Showing 6 changed files with 778 additions and 27 deletions.
15 changes: 9 additions & 6 deletions node_modules/minipass/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@ declare namespace Minipass {

type BufferOrString = Buffer | string

interface StringOptions {
interface SharedOptions {
async?: boolean
signal?: AbortSignal
}

interface StringOptions extends SharedOptions {
encoding: BufferEncoding
objectMode?: boolean
async?: boolean
}

interface BufferOptions {
interface BufferOptions extends SharedOptions {
encoding?: null | 'buffer'
objectMode?: boolean
async?: boolean
}

interface ObjectModeOptions {
interface ObjectModeOptions extends SharedOptions {
objectMode: true
async?: boolean
}

interface PipeOptions {
Expand Down Expand Up @@ -70,6 +72,7 @@ declare class Minipass<
readonly flowing: boolean
readonly writable: boolean
readonly readable: boolean
readonly aborted: boolean
readonly paused: boolean
readonly emittedEnd: boolean
readonly destroyed: boolean
Expand Down
55 changes: 43 additions & 12 deletions node_modules/minipass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -93,7 +97,7 @@ class PipeProxyErrors extends Pipe {
}
}

module.exports = class Minipass extends Stream {
class Minipass extends Stream {
constructor(options) {
super()
this[FLOWING] = false
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand All @@ -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') {
Expand Down Expand Up @@ -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
Loading

0 comments on commit 1f60a7e

Please sign in to comment.