Skip to content

Commit e940917

Browse files
committed
1 parent 875bd56 commit e940917

File tree

9 files changed

+902
-12
lines changed

9 files changed

+902
-12
lines changed

node_modules/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
!/brace-expansion
5353
!/builtins
5454
!/cacache
55+
!/cacache/node_modules/
56+
/cacache/node_modules/*
57+
!/cacache/node_modules/minipass
5558
!/chalk
5659
!/chownr
5760
!/ci-info
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) 2017-2022 npm, Inc., Isaac Z. Schlueter, and Contributors
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/// <reference types="node" />
2+
3+
// Note: marking anything protected or private in the exported
4+
// class will limit Minipass's ability to be used as the base
5+
// for mixin classes.
6+
import { EventEmitter } from 'events'
7+
import { Stream } from 'stream'
8+
9+
declare namespace Minipass {
10+
type Encoding = BufferEncoding | 'buffer' | null
11+
12+
interface Writable extends EventEmitter {
13+
end(): any
14+
write(chunk: any, ...args: any[]): any
15+
}
16+
17+
interface Readable extends EventEmitter {
18+
pause(): any
19+
resume(): any
20+
pipe(): any
21+
}
22+
23+
type DualIterable<T> = Iterable<T> & AsyncIterable<T>
24+
25+
type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string
26+
27+
type BufferOrString = Buffer | string
28+
29+
interface StringOptions {
30+
encoding: BufferEncoding
31+
objectMode?: boolean
32+
async?: boolean
33+
}
34+
35+
interface BufferOptions {
36+
encoding?: null | 'buffer'
37+
objectMode?: boolean
38+
async?: boolean
39+
}
40+
41+
interface ObjectModeOptions {
42+
objectMode: true
43+
async?: boolean
44+
}
45+
46+
interface PipeOptions {
47+
end?: boolean
48+
proxyErrors?: boolean
49+
}
50+
51+
type Options<T> = T extends string
52+
? StringOptions
53+
: T extends Buffer
54+
? BufferOptions
55+
: ObjectModeOptions
56+
}
57+
58+
declare class Minipass<
59+
RType extends any = Buffer,
60+
WType extends any = RType extends Minipass.BufferOrString
61+
? Minipass.ContiguousData
62+
: RType
63+
>
64+
extends Stream
65+
implements Minipass.DualIterable<RType>
66+
{
67+
static isStream(stream: any): stream is Minipass.Readable | Minipass.Writable
68+
69+
readonly bufferLength: number
70+
readonly flowing: boolean
71+
readonly writable: boolean
72+
readonly readable: boolean
73+
readonly paused: boolean
74+
readonly emittedEnd: boolean
75+
readonly destroyed: boolean
76+
77+
/**
78+
* Technically writable, but mutating it can change the type,
79+
* so is not safe to do in TypeScript.
80+
*/
81+
readonly objectMode: boolean
82+
async: boolean
83+
84+
/**
85+
* Note: encoding is not actually read-only, and setEncoding(enc)
86+
* exists. However, this type definition will insist that TypeScript
87+
* programs declare the type of a Minipass stream up front, and if
88+
* that type is string, then an encoding MUST be set in the ctor. If
89+
* the type is Buffer, then the encoding must be missing, or set to
90+
* 'buffer' or null. If the type is anything else, then objectMode
91+
* must be set in the constructor options. So there is effectively
92+
* no allowed way that a TS program can set the encoding after
93+
* construction, as doing so will destroy any hope of type safety.
94+
* TypeScript does not provide many options for changing the type of
95+
* an object at run-time, which is what changing the encoding does.
96+
*/
97+
readonly encoding: Minipass.Encoding
98+
// setEncoding(encoding: Encoding): void
99+
100+
// Options required if not reading buffers
101+
constructor(
102+
...args: RType extends Buffer
103+
? [] | [Minipass.Options<RType>]
104+
: [Minipass.Options<RType>]
105+
)
106+
107+
write(chunk: WType, cb?: () => void): boolean
108+
write(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): boolean
109+
read(size?: number): RType
110+
end(cb?: () => void): this
111+
end(chunk: any, cb?: () => void): this
112+
end(chunk: any, encoding?: Minipass.Encoding, cb?: () => void): this
113+
pause(): void
114+
resume(): void
115+
promise(): Promise<void>
116+
collect(): Promise<RType[]>
117+
118+
concat(): RType extends Minipass.BufferOrString ? Promise<RType> : never
119+
destroy(er?: any): void
120+
pipe<W extends Minipass.Writable>(dest: W, opts?: Minipass.PipeOptions): W
121+
unpipe<W extends Minipass.Writable>(dest: W): void
122+
123+
/**
124+
* alias for on()
125+
*/
126+
addEventHandler(event: string, listener: (...args: any[]) => any): this
127+
128+
on(event: string, listener: (...args: any[]) => any): this
129+
on(event: 'data', listener: (chunk: RType) => any): this
130+
on(event: 'error', listener: (error: any) => any): this
131+
on(
132+
event:
133+
| 'readable'
134+
| 'drain'
135+
| 'resume'
136+
| 'end'
137+
| 'prefinish'
138+
| 'finish'
139+
| 'close',
140+
listener: () => any
141+
): this
142+
143+
[Symbol.iterator](): Iterator<RType>
144+
[Symbol.asyncIterator](): AsyncIterator<RType>
145+
}
146+
147+
export = Minipass

0 commit comments

Comments
 (0)