1 | declare module "stream" {
|
2 | import * as events from "events";
|
3 |
|
4 | class internal extends events.EventEmitter {
|
5 | pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean; }): T;
|
6 | }
|
7 |
|
8 | namespace internal {
|
9 | class Stream extends internal { }
|
10 |
|
11 | interface ReadableOptions {
|
12 | highWaterMark?: number;
|
13 | encoding?: string;
|
14 | objectMode?: boolean;
|
15 | read?(this: Readable, size: number): void;
|
16 | destroy?(this: Readable, error: Error | null, callback: (error: Error | null) => void): void;
|
17 | autoDestroy?: boolean;
|
18 | }
|
19 |
|
20 | class Readable extends Stream implements NodeJS.ReadableStream {
|
21 | /**
|
22 | * A utility method for creating Readable Streams out of iterators.
|
23 | */
|
24 | static from(iterable: Iterable<any> | AsyncIterable<any>, options?: ReadableOptions): Readable;
|
25 |
|
26 | readable: boolean;
|
27 | readonly readableHighWaterMark: number;
|
28 | readonly readableLength: number;
|
29 | readonly readableObjectMode: boolean;
|
30 | destroyed: boolean;
|
31 | constructor(opts?: ReadableOptions);
|
32 | _read(size: number): void;
|
33 | read(size?: number): any;
|
34 | setEncoding(encoding: string): this;
|
35 | pause(): this;
|
36 | resume(): this;
|
37 | isPaused(): boolean;
|
38 | unpipe(destination?: NodeJS.WritableStream): this;
|
39 | unshift(chunk: any, encoding?: BufferEncoding): void;
|
40 | wrap(oldStream: NodeJS.ReadableStream): this;
|
41 | push(chunk: any, encoding?: string): boolean;
|
42 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
43 | destroy(error?: Error): void;
|
44 |
|
45 | /**
|
46 | * Event emitter
|
47 | * The defined events on documents including:
|
48 | * 1. close
|
49 | * 2. data
|
50 | * 3. end
|
51 | * 4. readable
|
52 | * 5. error
|
53 | */
|
54 | addListener(event: "close", listener: () => void): this;
|
55 | addListener(event: "data", listener: (chunk: any) => void): this;
|
56 | addListener(event: "end", listener: () => void): this;
|
57 | addListener(event: "readable", listener: () => void): this;
|
58 | addListener(event: "error", listener: (err: Error) => void): this;
|
59 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
60 |
|
61 | emit(event: "close"): boolean;
|
62 | emit(event: "data", chunk: any): boolean;
|
63 | emit(event: "end"): boolean;
|
64 | emit(event: "readable"): boolean;
|
65 | emit(event: "error", err: Error): boolean;
|
66 | emit(event: string | symbol, ...args: any[]): boolean;
|
67 |
|
68 | on(event: "close", listener: () => void): this;
|
69 | on(event: "data", listener: (chunk: any) => void): this;
|
70 | on(event: "end", listener: () => void): this;
|
71 | on(event: "readable", listener: () => void): this;
|
72 | on(event: "error", listener: (err: Error) => void): this;
|
73 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
74 |
|
75 | once(event: "close", listener: () => void): this;
|
76 | once(event: "data", listener: (chunk: any) => void): this;
|
77 | once(event: "end", listener: () => void): this;
|
78 | once(event: "readable", listener: () => void): this;
|
79 | once(event: "error", listener: (err: Error) => void): this;
|
80 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
81 |
|
82 | prependListener(event: "close", listener: () => void): this;
|
83 | prependListener(event: "data", listener: (chunk: any) => void): this;
|
84 | prependListener(event: "end", listener: () => void): this;
|
85 | prependListener(event: "readable", listener: () => void): this;
|
86 | prependListener(event: "error", listener: (err: Error) => void): this;
|
87 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
88 |
|
89 | prependOnceListener(event: "close", listener: () => void): this;
|
90 | prependOnceListener(event: "data", listener: (chunk: any) => void): this;
|
91 | prependOnceListener(event: "end", listener: () => void): this;
|
92 | prependOnceListener(event: "readable", listener: () => void): this;
|
93 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
94 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
95 |
|
96 | removeListener(event: "close", listener: () => void): this;
|
97 | removeListener(event: "data", listener: (chunk: any) => void): this;
|
98 | removeListener(event: "end", listener: () => void): this;
|
99 | removeListener(event: "readable", listener: () => void): this;
|
100 | removeListener(event: "error", listener: (err: Error) => void): this;
|
101 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
102 |
|
103 | [Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
104 | }
|
105 |
|
106 | interface WritableOptions {
|
107 | highWaterMark?: number;
|
108 | decodeStrings?: boolean;
|
109 | defaultEncoding?: string;
|
110 | objectMode?: boolean;
|
111 | emitClose?: boolean;
|
112 | write?(this: Writable, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
113 | writev?(this: Writable, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
114 | destroy?(this: Writable, error: Error | null, callback: (error: Error | null) => void): void;
|
115 | final?(this: Writable, callback: (error?: Error | null) => void): void;
|
116 | autoDestroy?: boolean;
|
117 | }
|
118 |
|
119 | class Writable extends Stream implements NodeJS.WritableStream {
|
120 | readonly writable: boolean;
|
121 | readonly writableFinished: boolean;
|
122 | readonly writableHighWaterMark: number;
|
123 | readonly writableLength: number;
|
124 | readonly writableObjectMode: boolean;
|
125 | destroyed: boolean;
|
126 | constructor(opts?: WritableOptions);
|
127 | _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
128 | _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
129 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
130 | _final(callback: (error?: Error | null) => void): void;
|
131 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
132 | write(chunk: any, encoding: string, cb?: (error: Error | null | undefined) => void): boolean;
|
133 | setDefaultEncoding(encoding: string): this;
|
134 | end(cb?: () => void): void;
|
135 | end(chunk: any, cb?: () => void): void;
|
136 | end(chunk: any, encoding: string, cb?: () => void): void;
|
137 | cork(): void;
|
138 | uncork(): void;
|
139 | destroy(error?: Error): void;
|
140 |
|
141 | /**
|
142 | * Event emitter
|
143 | * The defined events on documents including:
|
144 | * 1. close
|
145 | * 2. drain
|
146 | * 3. error
|
147 | * 4. finish
|
148 | * 5. pipe
|
149 | * 6. unpipe
|
150 | */
|
151 | addListener(event: "close", listener: () => void): this;
|
152 | addListener(event: "drain", listener: () => void): this;
|
153 | addListener(event: "error", listener: (err: Error) => void): this;
|
154 | addListener(event: "finish", listener: () => void): this;
|
155 | addListener(event: "pipe", listener: (src: Readable) => void): this;
|
156 | addListener(event: "unpipe", listener: (src: Readable) => void): this;
|
157 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
158 |
|
159 | emit(event: "close"): boolean;
|
160 | emit(event: "drain"): boolean;
|
161 | emit(event: "error", err: Error): boolean;
|
162 | emit(event: "finish"): boolean;
|
163 | emit(event: "pipe", src: Readable): boolean;
|
164 | emit(event: "unpipe", src: Readable): boolean;
|
165 | emit(event: string | symbol, ...args: any[]): boolean;
|
166 |
|
167 | on(event: "close", listener: () => void): this;
|
168 | on(event: "drain", listener: () => void): this;
|
169 | on(event: "error", listener: (err: Error) => void): this;
|
170 | on(event: "finish", listener: () => void): this;
|
171 | on(event: "pipe", listener: (src: Readable) => void): this;
|
172 | on(event: "unpipe", listener: (src: Readable) => void): this;
|
173 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
174 |
|
175 | once(event: "close", listener: () => void): this;
|
176 | once(event: "drain", listener: () => void): this;
|
177 | once(event: "error", listener: (err: Error) => void): this;
|
178 | once(event: "finish", listener: () => void): this;
|
179 | once(event: "pipe", listener: (src: Readable) => void): this;
|
180 | once(event: "unpipe", listener: (src: Readable) => void): this;
|
181 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
182 |
|
183 | prependListener(event: "close", listener: () => void): this;
|
184 | prependListener(event: "drain", listener: () => void): this;
|
185 | prependListener(event: "error", listener: (err: Error) => void): this;
|
186 | prependListener(event: "finish", listener: () => void): this;
|
187 | prependListener(event: "pipe", listener: (src: Readable) => void): this;
|
188 | prependListener(event: "unpipe", listener: (src: Readable) => void): this;
|
189 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
190 |
|
191 | prependOnceListener(event: "close", listener: () => void): this;
|
192 | prependOnceListener(event: "drain", listener: () => void): this;
|
193 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
194 | prependOnceListener(event: "finish", listener: () => void): this;
|
195 | prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
|
196 | prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
|
197 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
198 |
|
199 | removeListener(event: "close", listener: () => void): this;
|
200 | removeListener(event: "drain", listener: () => void): this;
|
201 | removeListener(event: "error", listener: (err: Error) => void): this;
|
202 | removeListener(event: "finish", listener: () => void): this;
|
203 | removeListener(event: "pipe", listener: (src: Readable) => void): this;
|
204 | removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
205 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
206 | }
|
207 |
|
208 | interface DuplexOptions extends ReadableOptions, WritableOptions {
|
209 | allowHalfOpen?: boolean;
|
210 | readableObjectMode?: boolean;
|
211 | writableObjectMode?: boolean;
|
212 | read?(this: Duplex, size: number): void;
|
213 | write?(this: Duplex, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
214 | writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
215 | final?(this: Duplex, callback: (error?: Error | null) => void): void;
|
216 | destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
|
217 | }
|
218 |
|
219 | // Note: Duplex extends both Readable and Writable.
|
220 | class Duplex extends Readable implements Writable {
|
221 | readonly writable: boolean;
|
222 | readonly writableFinished: boolean;
|
223 | readonly writableHighWaterMark: number;
|
224 | readonly writableLength: number;
|
225 | readonly writableObjectMode: boolean;
|
226 | constructor(opts?: DuplexOptions);
|
227 | _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
228 | _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
229 | _destroy(error: Error | null, callback: (error: Error | null) => void): void;
|
230 | _final(callback: (error?: Error | null) => void): void;
|
231 | write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
|
232 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
233 | setDefaultEncoding(encoding: string): this;
|
234 | end(cb?: () => void): void;
|
235 | end(chunk: any, cb?: () => void): void;
|
236 | end(chunk: any, encoding?: string, cb?: () => void): void;
|
237 | cork(): void;
|
238 | uncork(): void;
|
239 | }
|
240 |
|
241 | type TransformCallback = (error?: Error | null, data?: any) => void;
|
242 |
|
243 | interface TransformOptions extends DuplexOptions {
|
244 | read?(this: Transform, size: number): void;
|
245 | write?(this: Transform, chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
246 | writev?(this: Transform, chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
247 | final?(this: Transform, callback: (error?: Error | null) => void): void;
|
248 | destroy?(this: Transform, error: Error | null, callback: (error: Error | null) => void): void;
|
249 | transform?(this: Transform, chunk: any, encoding: string, callback: TransformCallback): void;
|
250 | flush?(this: Transform, callback: TransformCallback): void;
|
251 | }
|
252 |
|
253 | class Transform extends Duplex {
|
254 | constructor(opts?: TransformOptions);
|
255 | _transform(chunk: any, encoding: string, callback: TransformCallback): void;
|
256 | _flush(callback: TransformCallback): void;
|
257 | }
|
258 |
|
259 | class PassThrough extends Transform { }
|
260 |
|
261 | function finished(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream, callback: (err?: NodeJS.ErrnoException | null) => void): () => void;
|
262 | namespace finished {
|
263 | function __promisify__(stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream): Promise<void>;
|
264 | }
|
265 |
|
266 | function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
|
267 | function pipeline<T extends NodeJS.WritableStream>(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: T, callback?: (err: NodeJS.ErrnoException | null) => void): T;
|
268 | function pipeline<T extends NodeJS.WritableStream>(
|
269 | stream1: NodeJS.ReadableStream,
|
270 | stream2: NodeJS.ReadWriteStream,
|
271 | stream3: NodeJS.ReadWriteStream,
|
272 | stream4: T,
|
273 | callback?: (err: NodeJS.ErrnoException | null) => void,
|
274 | ): T;
|
275 | function pipeline<T extends NodeJS.WritableStream>(
|
276 | stream1: NodeJS.ReadableStream,
|
277 | stream2: NodeJS.ReadWriteStream,
|
278 | stream3: NodeJS.ReadWriteStream,
|
279 | stream4: NodeJS.ReadWriteStream,
|
280 | stream5: T,
|
281 | callback?: (err: NodeJS.ErrnoException | null) => void,
|
282 | ): T;
|
283 | function pipeline(streams: Array<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>, callback?: (err: NodeJS.ErrnoException | null) => void): NodeJS.WritableStream;
|
284 | function pipeline(
|
285 | stream1: NodeJS.ReadableStream,
|
286 | stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
|
287 | ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | ((err: NodeJS.ErrnoException | null) => void)>,
|
288 | ): NodeJS.WritableStream;
|
289 | namespace pipeline {
|
290 | function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.WritableStream): Promise<void>;
|
291 | function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: NodeJS.WritableStream): Promise<void>;
|
292 | function __promisify__(stream1: NodeJS.ReadableStream, stream2: NodeJS.ReadWriteStream, stream3: NodeJS.ReadWriteStream, stream4: NodeJS.WritableStream): Promise<void>;
|
293 | function __promisify__(
|
294 | stream1: NodeJS.ReadableStream,
|
295 | stream2: NodeJS.ReadWriteStream,
|
296 | stream3: NodeJS.ReadWriteStream,
|
297 | stream4: NodeJS.ReadWriteStream,
|
298 | stream5: NodeJS.WritableStream,
|
299 | ): Promise<void>;
|
300 | function __promisify__(streams: Array<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>): Promise<void>;
|
301 | function __promisify__(
|
302 | stream1: NodeJS.ReadableStream,
|
303 | stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
|
304 | ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream>,
|
305 | ): Promise<void>;
|
306 | }
|
307 |
|
308 | interface Pipe { }
|
309 | }
|
310 |
|
311 | export = internal;
|
312 | }
|