1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | import * as SafeBuffer from "safe-buffer";
|
11 |
|
12 | declare class StringDecoder {
|
13 | constructor(encoding?: BufferEncoding | string);
|
14 | write(buffer: Buffer): string;
|
15 | end(buffer?: Buffer): string;
|
16 | }
|
17 |
|
18 | interface _IEventEmitter {
|
19 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
20 | emit(event: string | symbol, ...args: any[]): boolean;
|
21 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
22 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
23 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
24 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
25 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
26 |
|
27 | removeAllListeners(event?: string | symbol): this;
|
28 | off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
29 | setMaxListeners(n: number): this;
|
30 | getMaxListeners(): number;
|
31 |
|
32 | listeners(eventName: string | symbol): Function[];
|
33 |
|
34 | rawListeners(eventName: string | symbol): Function[];
|
35 | listenerCount(eventName: string | symbol): number;
|
36 | eventNames(): Array<string | symbol>;
|
37 | }
|
38 |
|
39 | interface _IReadable extends _IEventEmitter {
|
40 | _read(size: number): void;
|
41 | read(size?: number): any;
|
42 | setEncoding(encoding: string): this;
|
43 | pause(): this;
|
44 | resume(): this;
|
45 | isPaused(): boolean;
|
46 | unpipe(destination?: _Readable.Writable): this;
|
47 | unshift(chunk: any): void;
|
48 | wrap(oldStream: _Readable.Readable): this;
|
49 | push(chunk: any, encoding?: string): boolean;
|
50 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
51 | destroy(error?: Error): this;
|
52 | }
|
53 |
|
54 | declare class _Readable implements _IReadable {
|
55 | readable: boolean;
|
56 | readonly readableFlowing: boolean | null;
|
57 | readonly readableHighWaterMark: number;
|
58 | readonly readableLength: number;
|
59 | _read(size: number): void;
|
60 | read(size?: number): any;
|
61 | setEncoding(encoding: string): this;
|
62 | pause(): this;
|
63 | resume(): this;
|
64 | isPaused(): boolean;
|
65 | unpipe(destination?: _Readable.Writable): this;
|
66 | unshift(chunk: any): void;
|
67 | wrap(oldStream: _Readable.Readable): this;
|
68 | push(chunk: any, encoding?: string): boolean;
|
69 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
70 | destroy(error?: Error): this;
|
71 |
|
72 | |
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | addListener(event: "close", listener: () => void): this;
|
82 | addListener(event: "data", listener: (chunk: any) => void): this;
|
83 | addListener(event: "end", listener: () => void): this;
|
84 | addListener(event: "readable", listener: () => void): this;
|
85 | addListener(event: "error", listener: (err: Error) => void): this;
|
86 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
87 |
|
88 | emit(event: "close"): boolean;
|
89 | emit(event: "data", chunk: any): boolean;
|
90 | emit(event: "end"): boolean;
|
91 | emit(event: "readable"): boolean;
|
92 | emit(event: "error", err: Error): boolean;
|
93 | emit(event: string | symbol, ...args: any[]): boolean;
|
94 |
|
95 | on(event: "close", listener: () => void): this;
|
96 | on(event: "data", listener: (chunk: any) => void): this;
|
97 | on(event: "end", listener: () => void): this;
|
98 | on(event: "readable", listener: () => void): this;
|
99 | on(event: "error", listener: (err: Error) => void): this;
|
100 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
101 |
|
102 | once(event: "close", listener: () => void): this;
|
103 | once(event: "data", listener: (chunk: any) => void): this;
|
104 | once(event: "end", listener: () => void): this;
|
105 | once(event: "readable", listener: () => void): this;
|
106 | once(event: "error", listener: (err: Error) => void): this;
|
107 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
108 |
|
109 | prependListener(event: "close", listener: () => void): this;
|
110 | prependListener(event: "data", listener: (chunk: any) => void): this;
|
111 | prependListener(event: "end", listener: () => void): this;
|
112 | prependListener(event: "readable", listener: () => void): this;
|
113 | prependListener(event: "error", listener: (err: Error) => void): this;
|
114 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
115 |
|
116 | prependOnceListener(event: "close", listener: () => void): this;
|
117 | prependOnceListener(event: "data", listener: (chunk: any) => void): this;
|
118 | prependOnceListener(event: "end", listener: () => void): this;
|
119 | prependOnceListener(event: "readable", listener: () => void): this;
|
120 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
121 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
122 |
|
123 | removeListener(event: "close", listener: () => void): this;
|
124 | removeListener(event: "data", listener: (chunk: any) => void): this;
|
125 | removeListener(event: "end", listener: () => void): this;
|
126 | removeListener(event: "readable", listener: () => void): this;
|
127 | removeListener(event: "error", listener: (err: Error) => void): this;
|
128 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
129 |
|
130 | removeAllListeners(event?: string | symbol): this;
|
131 | off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
132 | setMaxListeners(n: number): this;
|
133 | getMaxListeners(): number;
|
134 |
|
135 | listeners(eventName: string | symbol): Function[];
|
136 |
|
137 | rawListeners(eventName: string | symbol): Function[];
|
138 | listenerCount(eventName: string | symbol): number;
|
139 | eventNames(): Array<string | symbol>;
|
140 |
|
141 | [Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
142 |
|
143 |
|
144 | _readableState: _Readable.ReadableState;
|
145 | destroyed: boolean;
|
146 |
|
147 | constructor(options?: _Readable.ReadableOptions);
|
148 |
|
149 | _undestroy(): void;
|
150 | }
|
151 |
|
152 | declare namespace _Readable {
|
153 |
|
154 | interface Entry<D> {
|
155 | data: D;
|
156 | next: Entry<D> | null;
|
157 | }
|
158 |
|
159 | interface BufferList<D extends SafeBuffer.Buffer = SafeBuffer.Buffer> {
|
160 | head: Entry<D>;
|
161 | tail: Entry<D>;
|
162 | length: number;
|
163 |
|
164 | push(v: D): void;
|
165 | unshift(v: D): void;
|
166 | shift(): D;
|
167 | clear(): void;
|
168 | join(s: any): string;
|
169 | concat(n: number): D;
|
170 | }
|
171 |
|
172 |
|
173 | interface Destroy {
|
174 | destroy(this: Readable | Writable, error: Error | null, callback?: (error: Error | null) => void): Readable | Writable;
|
175 | undestroy(this: Readable | Writable): void;
|
176 | }
|
177 |
|
178 |
|
179 | type DuplexOptions = ReadableOptions & WritableOptions & {
|
180 | allowHalfOpen?: boolean | undefined;
|
181 | readable?: boolean | undefined;
|
182 | writable?: boolean | undefined;
|
183 | read?(this: Duplex, size: number): void;
|
184 | write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
185 | writev?(this: Duplex, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
|
186 | final?(this: Duplex, callback: (error?: Error | null) => void): void;
|
187 | destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
|
188 | };
|
189 |
|
190 | type _IDuplex = _IReadable & _IWritable;
|
191 |
|
192 | class Duplex extends _Writable implements _IDuplex, /*extends*/_Readable, Duplex {
|
193 | /**
|
194 | * This is a dummy function required to retain type compatibility to node.
|
195 | * @deprecated DO NOT USE
|
196 | */
|
197 | static from(source: any): any;
|
198 | allowHalfOpen: boolean;
|
199 | destroyed: boolean;
|
200 | // Readable
|
201 | readable: boolean;
|
202 | readonly readableEncoding: BufferEncoding | null;
|
203 | readonly readableEnded: boolean;
|
204 | readonly readableFlowing: boolean | null;
|
205 | readonly readableHighWaterMark: number;
|
206 | readonly readableLength: number;
|
207 | readonly readableObjectMode: boolean;
|
208 | readonly writableObjectMode: boolean;
|
209 |
|
210 | readonly readableAborted: never;
|
211 | readonly readableDidRead: never;
|
212 | readonly writableEnded: never;
|
213 | readonly writableFinished: never;
|
214 | readonly writableCorked: never;
|
215 |
|
216 | _readableState: ReadableState;
|
217 |
|
218 | _read(size?: number): void;
|
219 | read(size?: number): any;
|
220 | setEncoding(enc: BufferEncoding): this;
|
221 | resume(): this;
|
222 | pause(): this;
|
223 | isPaused(): boolean;
|
224 | unpipe(dest?: Writable): this;
|
225 | unshift(chunk: any): boolean;
|
226 | wrap(oldStream: Readable): this;
|
227 | push(chunk: any, encoding?: BufferEncoding): boolean;
|
228 | _destroy(err: Error | null, callback: (error: Error | null) => void): void;
|
229 | destroy(err?: Error, callback?: (error: Error | null) => void): this;
|
230 | pipe<S extends _IWritable>(dest: S, pipeOpts?: { end?: boolean | undefined }): S;
|
231 | addListener(ev: string | symbol, fn: (...args: any[]) => void): this;
|
232 | on(ev: string | symbol, fn: (...args: any[]) => void): this;
|
233 |
|
234 | _undestroy(): void;
|
235 | [Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
236 | // end-Readable
|
237 |
|
238 | constructor(options?: DuplexOptions);
|
239 | }
|
240 |
|
241 | // ==== _stream_passthrough ====
|
242 | class PassThrough extends Transform {
|
243 | constructor(options?: TransformOptions);
|
244 |
|
245 | _transform<T>(chunk: T, encoding: BufferEncoding | string | null | undefined, callback: (error?: Error, data?: T) => void): void;
|
246 | }
|
247 |
|
248 | // ==== _stream_readable ====
|
249 | interface ReadableStateOptions {
|
250 | defaultEncoding?: BufferEncoding | undefined;
|
251 | encoding?: BufferEncoding | undefined;
|
252 | highWaterMark?: number | undefined;
|
253 | objectMode?: boolean | undefined;
|
254 | readableObjectMode?: boolean | undefined;
|
255 | readableHighWaterMark?: number | undefined;
|
256 | }
|
257 |
|
258 | interface ReadableState {
|
259 | objectMode: boolean;
|
260 | highWaterMark: number;
|
261 | buffer: BufferList<any>;
|
262 | length: number;
|
263 | pipes: any;
|
264 | pipesCount: number;
|
265 | flowing: any;
|
266 | ended: boolean;
|
267 | endEmitted: boolean;
|
268 | reading: boolean;
|
269 | sync: boolean;
|
270 | needReadable: boolean;
|
271 | emittedReadable: boolean;
|
272 | readableListening: boolean;
|
273 | resumeScheduled: boolean;
|
274 | destroyed: boolean;
|
275 | awaitDrain: number;
|
276 | defaultEncoding: BufferEncoding;
|
277 | readingMore: boolean;
|
278 | decoder: StringDecoder | null;
|
279 | encoding: BufferEncoding | null;
|
280 |
|
281 | // new (options: ReadableStateOptions, stream: _Readable): ReadableState;
|
282 | }
|
283 |
|
284 | type ReadableOptions = ReadableStateOptions & {
|
285 | read?(this: _IReadable, size: number): void;
|
286 | destroy?(this: _IReadable, error: Error | null, callback: (error: Error | null) => void): void;
|
287 | };
|
288 |
|
289 | class Readable extends _Readable {
|
290 | readonly readableAborted: never;
|
291 | readonly readableDidRead: never;
|
292 | readonly readableEncoding: never;
|
293 | readonly readableEnded: never;
|
294 | readonly readableObjectMode: never;
|
295 |
|
296 | constructor(options?: ReadableOptions);
|
297 | pipe<T extends _IWritable>(destination: T, options?: { end?: boolean | undefined; }): T;
|
298 | }
|
299 |
|
300 | // ==== _stream_transform ====
|
301 | type TransformOptions = ReadableOptions & WritableOptions & {
|
302 | read?(this: _ITransform, size: number): void;
|
303 | write?(this: _ITransform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
304 | writev?(this: _ITransform, chunks: Array<{ chunk: any, encoding: BufferEncoding }>, callback: (error?: Error | null) => void): void;
|
305 | final?(this: _ITransform, callback: (error?: Error | null) => void): void;
|
306 | destroy?(this: _ITransform, error: Error | null, callback: (error: Error | null) => void): void;
|
307 | transform?(this: _ITransform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void;
|
308 | flush?(callback: (error?: Error | null, data?: any) => void): void;
|
309 | };
|
310 |
|
311 | interface _ITransform extends _IDuplex {
|
312 | _transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void;
|
313 | _flush(callback: (error?: Error | null, data?: any) => void): void;
|
314 | }
|
315 |
|
316 | class Transform extends Duplex {
|
317 | _transformState: {
|
318 | afterTransform: (this: Transform, er: any, data: any) => void | boolean;
|
319 | needTransform: boolean;
|
320 | transforming: boolean;
|
321 | writecb: ((err: any) => any) | null;
|
322 | writechunk: any; // TODO
|
323 | writeencoding: BufferEncoding | null;
|
324 | };
|
325 |
|
326 | constructor(options?: TransformOptions);
|
327 |
|
328 | _transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void;
|
329 | _flush(callback: (error?: Error | null, data?: any) => void): void;
|
330 | }
|
331 |
|
332 | // ==== _stream_writable ====
|
333 | interface CorkedRequest {
|
334 | next: any;
|
335 | entry: any;
|
336 | finish(): void;
|
337 | }
|
338 |
|
339 | interface BufferRequest {
|
340 | chunk: any; // TODO
|
341 | encoding: BufferEncoding;
|
342 | isBuf: boolean;
|
343 | callback: (error?: Error | null) => void;
|
344 | next: BufferRequest | null;
|
345 | }
|
346 |
|
347 | interface WritableStateOptions {
|
348 | decodeStrings?: boolean | undefined;
|
349 | defaultEncoding?: BufferEncoding | undefined;
|
350 | highWaterMark?: number | undefined;
|
351 | objectMode?: boolean | undefined;
|
352 | writableObjectMode?: boolean | undefined;
|
353 | writableHighWaterMark?: number | undefined;
|
354 | }
|
355 |
|
356 | interface WritableState {
|
357 | buffer: BufferRequest[];
|
358 | objectMode: boolean;
|
359 | highWaterMark: number;
|
360 | finalCalled: boolean;
|
361 | needDrain: boolean;
|
362 | ending: boolean;
|
363 | ended: boolean;
|
364 | finished: boolean;
|
365 | destroyed: boolean;
|
366 | decodeStrings: boolean;
|
367 | defaultEncoding: BufferEncoding;
|
368 | length: number;
|
369 | writing: boolean;
|
370 | corked: number;
|
371 | sync: boolean;
|
372 | bufferProcessing: boolean;
|
373 | writelen: number;
|
374 | pendingcb: number;
|
375 | prefinished: boolean;
|
376 | errorEmitted: boolean;
|
377 | bufferedRequestCount: number;
|
378 | writecb: ((err?: Error | null) => void) | null;
|
379 | onwrite: (er?: Error | null) => any;
|
380 | bufferedRequest: BufferRequest | null;
|
381 | lastBufferedRequest: BufferRequest | null;
|
382 | corkedRequestsFree: CorkedRequest;
|
383 |
|
384 |
|
385 |
|
386 | getBuffer(): BufferRequest[];
|
387 | }
|
388 |
|
389 | type WritableOptions = WritableStateOptions & {
|
390 | write?(this: _IWritable, chunk: any, encoding: BufferEncoding | string, callback: (error?: Error | null) => void): void;
|
391 | writev?(this: _IWritable, chunk: ArrayLike<{ chunk: any; encoding: BufferEncoding | string }>, callback: (error?: Error | null) => void): void;
|
392 | destroy?(this: _IWritable, error: Error | null, callback: (error: Error | null) => void): void;
|
393 | final?(this: _IWritable, callback: (error?: Error | null) => void): void;
|
394 | };
|
395 |
|
396 | interface _IWritable extends _IEventEmitter {
|
397 | writable: boolean;
|
398 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
399 | write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
|
400 | end(cb?: () => void): this;
|
401 | end(data: string | Uint8Array, cb?: () => void): this;
|
402 | end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
|
403 | }
|
404 |
|
405 | class _Writable extends Stream implements _IWritable {
|
406 | writable: boolean;
|
407 | readonly writableHighWaterMark: number;
|
408 | readonly writableLength: number;
|
409 | constructor(opts?: WritableOptions);
|
410 | _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
411 | _writev?(chunks: Array<{ chunk: any, encoding: string }>, callback: (error?: Error | null) => void): void;
|
412 | _destroy(error: Error | null, callback: (error: Error | null) => void): void;
|
413 | _final(callback: (error?: Error | null) => void): void;
|
414 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
415 | write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
|
416 | setDefaultEncoding(encoding: string): this;
|
417 | end(cb?: () => void): this;
|
418 | end(chunk: any, cb?: () => void): this;
|
419 | end(chunk: any, encoding?: string, cb?: () => void): this;
|
420 | cork(): void;
|
421 | uncork(): void;
|
422 | destroy(error?: Error): this;
|
423 |
|
424 | /**
|
425 | * Event emitter
|
426 | * The defined events on documents including:
|
427 | * 1. close
|
428 | * 2. drain
|
429 | * 3. error
|
430 | * 4. finish
|
431 | * 5. pipe
|
432 | * 6. unpipe
|
433 | */
|
434 | addListener(event: "close", listener: () => void): this;
|
435 | addListener(event: "drain", listener: () => void): this;
|
436 | addListener(event: "error", listener: (err: Error) => void): this;
|
437 | addListener(event: "finish", listener: () => void): this;
|
438 | addListener(event: "pipe", listener: (src: Readable) => void): this;
|
439 | addListener(event: "unpipe", listener: (src: Readable) => void): this;
|
440 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
441 |
|
442 | emit(event: "close"): boolean;
|
443 | emit(event: "drain"): boolean;
|
444 | emit(event: "error", err: Error): boolean;
|
445 | emit(event: "finish"): boolean;
|
446 | emit(event: "pipe", src: Readable): boolean;
|
447 | emit(event: "unpipe", src: Readable): boolean;
|
448 | emit(event: string | symbol, ...args: any[]): boolean;
|
449 |
|
450 | on(event: "close", listener: () => void): this;
|
451 | on(event: "drain", listener: () => void): this;
|
452 | on(event: "error", listener: (err: Error) => void): this;
|
453 | on(event: "finish", listener: () => void): this;
|
454 | on(event: "pipe", listener: (src: Readable) => void): this;
|
455 | on(event: "unpipe", listener: (src: Readable) => void): this;
|
456 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
457 |
|
458 | once(event: "close", listener: () => void): this;
|
459 | once(event: "drain", listener: () => void): this;
|
460 | once(event: "error", listener: (err: Error) => void): this;
|
461 | once(event: "finish", listener: () => void): this;
|
462 | once(event: "pipe", listener: (src: Readable) => void): this;
|
463 | once(event: "unpipe", listener: (src: Readable) => void): this;
|
464 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
465 |
|
466 | prependListener(event: "close", listener: () => void): this;
|
467 | prependListener(event: "drain", listener: () => void): this;
|
468 | prependListener(event: "error", listener: (err: Error) => void): this;
|
469 | prependListener(event: "finish", listener: () => void): this;
|
470 | prependListener(event: "pipe", listener: (src: Readable) => void): this;
|
471 | prependListener(event: "unpipe", listener: (src: Readable) => void): this;
|
472 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
473 |
|
474 | prependOnceListener(event: "close", listener: () => void): this;
|
475 | prependOnceListener(event: "drain", listener: () => void): this;
|
476 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
477 | prependOnceListener(event: "finish", listener: () => void): this;
|
478 | prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
|
479 | prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
|
480 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
481 |
|
482 | removeListener(event: "close", listener: () => void): this;
|
483 | removeListener(event: "drain", listener: () => void): this;
|
484 | removeListener(event: "error", listener: (err: Error) => void): this;
|
485 | removeListener(event: "finish", listener: () => void): this;
|
486 | removeListener(event: "pipe", listener: (src: Readable) => void): this;
|
487 | removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
488 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
489 |
|
490 | // static WritableState: WritableState;
|
491 | // private static realHasInstance: (obj: any) => boolean;
|
492 | destroyed: boolean;
|
493 | _writableState: WritableState;
|
494 |
|
495 | _undestroy(): void;
|
496 | }
|
497 |
|
498 | class Writable extends _Writable {
|
499 | readonly writableEnded: never;
|
500 | readonly writableFinished: never;
|
501 | readonly writableObjectMode: never;
|
502 | readonly writableCorked: never;
|
503 |
|
504 | constructor(opts?: WritableOptions);
|
505 | }
|
506 |
|
507 | class Stream extends _Readable {
|
508 | constructor(options?: ReadableOptions);
|
509 | pipe<T extends _IWritable>(destination: T, options?: { end?: boolean | undefined; }): T;
|
510 | }
|
511 | }
|
512 |
|
513 | export = _Readable;
|
514 | export as namespace _Readable;
|