UNPKG

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