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