source: node_modules/minipass/index.d.ts@ 81bc7da

finki-main main
Last change on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/// <reference types="node" />
2import { EventEmitter } from 'events'
3import { Stream } from 'stream'
4
5declare namespace Minipass {
6 type Encoding = BufferEncoding | 'buffer' | null
7
8 interface Writable extends EventEmitter {
9 end(): any
10 write(chunk: any, ...args: any[]): any
11 }
12
13 interface Readable extends EventEmitter {
14 pause(): any
15 resume(): any
16 pipe(): any
17 }
18
19 interface Pipe<R, W> {
20 src: Minipass<R, W>
21 dest: Writable
22 opts: PipeOptions
23 }
24
25 type DualIterable<T> = Iterable<T> & AsyncIterable<T>
26
27 type ContiguousData = Buffer | ArrayBufferLike | ArrayBufferView | string
28
29 type BufferOrString = Buffer | string
30
31 interface StringOptions {
32 encoding: BufferEncoding
33 objectMode?: boolean
34 async?: boolean
35 }
36
37 interface BufferOptions {
38 encoding?: null | 'buffer'
39 objectMode?: boolean
40 async?: boolean
41 }
42
43 interface ObjectModeOptions {
44 objectMode: true
45 async?: boolean
46 }
47
48 interface PipeOptions {
49 end?: boolean
50 proxyErrors?: boolean
51 }
52
53 type Options<T> = T extends string
54 ? StringOptions
55 : T extends Buffer
56 ? BufferOptions
57 : ObjectModeOptions
58}
59
60declare class Minipass<
61 RType extends any = Buffer,
62 WType extends any = RType extends Minipass.BufferOrString
63 ? Minipass.ContiguousData
64 : RType
65 >
66 extends Stream
67 implements Minipass.DualIterable<RType>
68{
69 static isStream(stream: any): stream is Minipass.Readable | Minipass.Writable
70
71 readonly bufferLength: number
72 readonly flowing: boolean
73 readonly writable: boolean
74 readonly readable: boolean
75 readonly paused: boolean
76 readonly emittedEnd: boolean
77 readonly destroyed: boolean
78
79 /**
80 * Not technically private or readonly, but not safe to mutate.
81 */
82 private readonly buffer: RType[]
83 private readonly pipes: Minipass.Pipe<RType, WType>[]
84
85 /**
86 * Technically writable, but mutating it can change the type,
87 * so is not safe to do in TypeScript.
88 */
89 readonly objectMode: boolean
90 async: boolean
91
92 /**
93 * Note: encoding is not actually read-only, and setEncoding(enc)
94 * exists. However, this type definition will insist that TypeScript
95 * programs declare the type of a Minipass stream up front, and if
96 * that type is string, then an encoding MUST be set in the ctor. If
97 * the type is Buffer, then the encoding must be missing, or set to
98 * 'buffer' or null. If the type is anything else, then objectMode
99 * must be set in the constructor options. So there is effectively
100 * no allowed way that a TS program can set the encoding after
101 * construction, as doing so will destroy any hope of type safety.
102 * TypeScript does not provide many options for changing the type of
103 * an object at run-time, which is what changing the encoding does.
104 */
105 readonly encoding: Minipass.Encoding
106 // setEncoding(encoding: Encoding): void
107
108 // Options required if not reading buffers
109 constructor(
110 ...args: RType extends Buffer
111 ? [] | [Minipass.Options<RType>]
112 : [Minipass.Options<RType>]
113 )
114
115 write(chunk: WType, cb?: () => void): boolean
116 write(chunk: WType, encoding?: Minipass.Encoding, cb?: () => void): boolean
117 read(size?: number): RType
118 end(cb?: () => void): this
119 end(chunk: any, cb?: () => void): this
120 end(chunk: any, encoding?: Minipass.Encoding, cb?: () => void): this
121 pause(): void
122 resume(): void
123 promise(): Promise<void>
124 collect(): Promise<RType[]>
125
126 concat(): RType extends Minipass.BufferOrString ? Promise<RType> : never
127 destroy(er?: any): void
128 pipe<W extends Minipass.Writable>(dest: W, opts?: Minipass.PipeOptions): W
129 unpipe<W extends Minipass.Writable>(dest: W): void
130
131 /**
132 * alias for on()
133 */
134 addEventHandler(event: string, listener: (...args: any[]) => any): this
135
136 on(event: string, listener: (...args: any[]) => any): this
137 on(event: 'data', listener: (chunk: RType) => any): this
138 on(event: 'error', listener: (error: any) => any): this
139 on(
140 event:
141 | 'readable'
142 | 'drain'
143 | 'resume'
144 | 'end'
145 | 'prefinish'
146 | 'finish'
147 | 'close',
148 listener: () => any
149 ): this
150
151 [Symbol.iterator](): Iterator<RType>
152 [Symbol.asyncIterator](): AsyncIterator<RType>
153}
154
155export = Minipass
Note: See TracBrowser for help on using the repository browser.