1 |
|
2 |
|
3 | import * as SafeBuffer from "safe-buffer";
|
4 | import type * as NodeStream from "stream";
|
5 |
|
6 | declare class StringDecoder {
|
7 | constructor(encoding?: BufferEncoding | string);
|
8 | write(buffer: Buffer): string;
|
9 | end(buffer?: Buffer): string;
|
10 | }
|
11 |
|
12 | type Is<T extends U, U> = T;
|
13 | declare var NoAsyncDispose: {
|
14 | new(
|
15 | ...arguments: any[]
|
16 | ): typeof globalThis.Symbol extends { readonly asyncDispose: Is<infer S, symbol> }
|
17 | ? symbol extends S ? {} : { [P in S]: never }
|
18 | : {};
|
19 | };
|
20 |
|
21 | type ComposeFnParam = (source: any) => void;
|
22 |
|
23 | interface _IEventEmitter {
|
24 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
25 | emit(event: string | symbol, ...args: any[]): boolean;
|
26 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
27 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
28 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
29 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
30 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
31 |
|
32 | removeAllListeners(event?: string | symbol): this;
|
33 | off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
34 | setMaxListeners(n: number): this;
|
35 | getMaxListeners(): number;
|
36 |
|
37 | listeners(eventName: string | symbol): Function[];
|
38 |
|
39 | rawListeners(eventName: string | symbol): Function[];
|
40 | listenerCount(eventName: string | symbol): number;
|
41 | eventNames(): Array<string | symbol>;
|
42 | }
|
43 |
|
44 | interface SignalOption {
|
45 | signal?: AbortSignal;
|
46 | }
|
47 | interface ArrayOptions extends SignalOption {
|
48 | concurrency?: number;
|
49 | }
|
50 |
|
51 | interface _IReadable extends _IEventEmitter {
|
52 | _read(size: number): void;
|
53 | read(size?: number): any;
|
54 | setEncoding(encoding: string): this;
|
55 | pause(): this;
|
56 | resume(): this;
|
57 | isPaused(): boolean;
|
58 | unpipe(destination?: _Readable.Writable): this;
|
59 | unshift(chunk: any): void;
|
60 | wrap(oldStream: _Readable.Readable): this;
|
61 | push(chunk: any, encoding?: string): boolean;
|
62 | iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
|
63 | map(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): _Readable.Readable;
|
64 | filter(
|
65 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
66 | options?: ArrayOptions,
|
67 | ): _Readable.Readable;
|
68 | forEach(fn: (data: any, options?: SignalOption) => void | Promise<void>, options?: ArrayOptions): Promise<void>;
|
69 | toArray(options?: SignalOption): Promise<any[]>;
|
70 | some(
|
71 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
72 | options?: ArrayOptions,
|
73 | ): Promise<boolean>;
|
74 | find<T>(fn: (data: any, options?: SignalOption) => data is T, options?: ArrayOptions): Promise<T | undefined>;
|
75 | find(fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>, options?: ArrayOptions): Promise<any>;
|
76 | every(
|
77 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
78 | options?: ArrayOptions,
|
79 | ): Promise<boolean>;
|
80 | flatMap(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): _Readable.Readable;
|
81 | drop(limit: number, options?: SignalOption): _Readable.Readable;
|
82 | take(limit: number, options?: SignalOption): _Readable.Readable;
|
83 | asIndexedPairs(options?: SignalOption): _Readable.Readable;
|
84 | reduce<T = any>(
|
85 | fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
86 | initial?: undefined,
|
87 | options?: Pick<ArrayOptions, "signal">,
|
88 | ): Promise<T>;
|
89 | reduce<T = any>(
|
90 | fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
91 | initial: T,
|
92 | options?: Pick<ArrayOptions, "signal">,
|
93 | ): Promise<T>;
|
94 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
95 | destroy(error?: Error): this;
|
96 | }
|
97 |
|
98 | declare class _Readable extends NoAsyncDispose implements _IReadable {
|
99 | readable: boolean;
|
100 | readonly readableFlowing: boolean | null;
|
101 | readonly readableHighWaterMark: number;
|
102 | readonly readableLength: number;
|
103 | readonly closed: boolean;
|
104 | readonly errored: Error | null;
|
105 | static from(iterable: Iterable<any> | AsyncIterable<any>, options?: _Readable.ReadableOptions): _Readable.Readable;
|
106 | _read(size: number): void;
|
107 | read(size?: number): any;
|
108 | setEncoding(encoding: string): this;
|
109 | pause(): this;
|
110 | resume(): this;
|
111 | isPaused(): boolean;
|
112 | unpipe(destination?: _Readable.Writable): this;
|
113 | unshift(chunk: any): void;
|
114 | wrap(oldStream: _Readable.Readable): this;
|
115 | push(chunk: any, encoding?: string): boolean;
|
116 | map(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): _Readable.Readable;
|
117 | filter(
|
118 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
119 | options?: ArrayOptions,
|
120 | ): _Readable.Readable;
|
121 | forEach(fn: (data: any, options?: SignalOption) => void | Promise<void>, options?: ArrayOptions): Promise<void>;
|
122 | toArray(options?: SignalOption): Promise<any[]>;
|
123 | some(
|
124 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
125 | options?: ArrayOptions,
|
126 | ): Promise<boolean>;
|
127 | find<T>(fn: (data: any, options?: SignalOption) => data is T, options?: ArrayOptions): Promise<T | undefined>;
|
128 | find(fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>, options?: ArrayOptions): Promise<any>;
|
129 | every(
|
130 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
131 | options?: ArrayOptions,
|
132 | ): Promise<boolean>;
|
133 | flatMap(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): _Readable.Readable;
|
134 | drop(limit: number, options?: SignalOption): _Readable.Readable;
|
135 | take(limit: number, options?: SignalOption): _Readable.Readable;
|
136 | asIndexedPairs(options?: SignalOption): _Readable.Readable;
|
137 | reduce<T = any>(
|
138 | fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
139 | initial?: undefined,
|
140 | options?: Pick<ArrayOptions, "signal">,
|
141 | ): Promise<T>;
|
142 | reduce<T = any>(
|
143 | fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
144 | initial: T,
|
145 | options?: Pick<ArrayOptions, "signal">,
|
146 | ): Promise<T>;
|
147 | _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
148 | destroy(error?: Error): this;
|
149 |
|
150 | /**
|
151 | * Event emitter
|
152 | * The defined events on documents including:
|
153 | * 1. close
|
154 | * 2. data
|
155 | * 3. end
|
156 | * 4. readable
|
157 | * 5. error
|
158 | */
|
159 | addListener(event: "close", listener: () => void): this;
|
160 | addListener(event: "data", listener: (chunk: any) => void): this;
|
161 | addListener(event: "end", listener: () => void): this;
|
162 | addListener(event: "readable", listener: () => void): this;
|
163 | addListener(event: "error", listener: (err: Error) => void): this;
|
164 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
165 |
|
166 | emit(event: "close"): boolean;
|
167 | emit(event: "data", chunk: any): boolean;
|
168 | emit(event: "end"): boolean;
|
169 | emit(event: "readable"): boolean;
|
170 | emit(event: "error", err: Error): boolean;
|
171 | emit(event: string | symbol, ...args: any[]): boolean;
|
172 |
|
173 | on(event: "close", listener: () => void): this;
|
174 | on(event: "data", listener: (chunk: any) => void): this;
|
175 | on(event: "end", listener: () => void): this;
|
176 | on(event: "readable", listener: () => void): this;
|
177 | on(event: "error", listener: (err: Error) => void): this;
|
178 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
179 |
|
180 | once(event: "close", listener: () => void): this;
|
181 | once(event: "data", listener: (chunk: any) => void): this;
|
182 | once(event: "end", listener: () => void): this;
|
183 | once(event: "readable", listener: () => void): this;
|
184 | once(event: "error", listener: (err: Error) => void): this;
|
185 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
186 |
|
187 | prependListener(event: "close", listener: () => void): this;
|
188 | prependListener(event: "data", listener: (chunk: any) => void): this;
|
189 | prependListener(event: "end", listener: () => void): this;
|
190 | prependListener(event: "readable", listener: () => void): this;
|
191 | prependListener(event: "error", listener: (err: Error) => void): this;
|
192 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
193 |
|
194 | prependOnceListener(event: "close", listener: () => void): this;
|
195 | prependOnceListener(event: "data", listener: (chunk: any) => void): this;
|
196 | prependOnceListener(event: "end", listener: () => void): this;
|
197 | prependOnceListener(event: "readable", listener: () => void): this;
|
198 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
199 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
200 |
|
201 | removeListener(event: "close", listener: () => void): this;
|
202 | removeListener(event: "data", listener: (chunk: any) => void): this;
|
203 | removeListener(event: "end", listener: () => void): this;
|
204 | removeListener(event: "readable", listener: () => void): this;
|
205 | removeListener(event: "error", listener: (err: Error) => void): this;
|
206 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
207 |
|
208 | removeAllListeners(event?: string | symbol): this;
|
209 | off(eventName: string | symbol, listener: (...args: any[]) => void): this;
|
210 | setMaxListeners(n: number): this;
|
211 | getMaxListeners(): number;
|
212 | // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
213 | listeners(eventName: string | symbol): Function[];
|
214 | // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
|
215 | rawListeners(eventName: string | symbol): Function[];
|
216 | listenerCount(eventName: string | symbol): number;
|
217 | eventNames(): Array<string | symbol>;
|
218 |
|
219 | iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
|
220 | [Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
221 |
|
222 | // static ReadableState: _Readable.ReadableState;
|
223 | _readableState: _Readable.ReadableState;
|
224 | destroyed: boolean;
|
225 |
|
226 | constructor(options?: _Readable.ReadableOptions);
|
227 |
|
228 | _undestroy(): void;
|
229 | }
|
230 |
|
231 | declare namespace _Readable {
|
232 | // ==== BufferList ====
|
233 | interface Entry<D> {
|
234 | data: D;
|
235 | next: Entry<D> | null;
|
236 | }
|
237 |
|
238 | interface BufferList<D extends SafeBuffer.Buffer = SafeBuffer.Buffer> {
|
239 | head: Entry<D>;
|
240 | tail: Entry<D>;
|
241 | length: number;
|
242 |
|
243 | push(v: D): void;
|
244 | unshift(v: D): void;
|
245 | shift(): D;
|
246 | clear(): void;
|
247 | join(s: any): string;
|
248 | concat(n: number): D;
|
249 | }
|
250 |
|
251 | // ==== destroy ====
|
252 | interface Destroy {
|
253 | destroy(
|
254 | this: Readable | Writable,
|
255 | error: Error | null,
|
256 | callback?: (error: Error | null) => void,
|
257 | ): Readable | Writable;
|
258 | undestroy(this: Readable | Writable): void;
|
259 | }
|
260 |
|
261 | // ==== _stream_duplex ====
|
262 | type DuplexOptions = ReadableOptions & WritableOptions & {
|
263 | allowHalfOpen?: boolean | undefined;
|
264 | readable?: boolean | undefined;
|
265 | writable?: boolean | undefined;
|
266 | read?(this: Duplex, size: number): void;
|
267 | write?(this: Duplex, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
268 | writev?(
|
269 | this: Duplex,
|
270 | chunks: Array<{ chunk: any; encoding: BufferEncoding }>,
|
271 | callback: (error?: Error | null) => void,
|
272 | ): void;
|
273 | final?(this: Duplex, callback: (error?: Error | null) => void): void;
|
274 | destroy?(this: Duplex, error: Error | null, callback: (error: Error | null) => void): void;
|
275 | };
|
276 |
|
277 | type _IDuplex = _IReadable & _IWritable;
|
278 |
|
279 | class Duplex extends _Writable implements _IDuplex, /*extends*/ _Readable, Duplex {
|
280 | static from(
|
281 | src:
|
282 | | Stream
|
283 | | Blob
|
284 | | ArrayBuffer
|
285 | | string
|
286 | | Iterable<any>
|
287 | | AsyncIterable<any>
|
288 | | AsyncGeneratorFunction
|
289 | | Promise<any>
|
290 | | { writable?: Writable; readable?: _Readable },
|
291 | ): Duplex;
|
292 | allowHalfOpen: boolean;
|
293 | destroyed: boolean;
|
294 | // Readable
|
295 | readable: boolean;
|
296 | readonly readableEncoding: BufferEncoding | null;
|
297 | readonly readableEnded: boolean;
|
298 | readonly readableFlowing: boolean | null;
|
299 | readonly readableHighWaterMark: number;
|
300 | readonly readableLength: number;
|
301 | readonly readableObjectMode: boolean;
|
302 | readonly writableObjectMode: boolean;
|
303 |
|
304 | readonly readableAborted: boolean;
|
305 | readonly readableDidRead: boolean;
|
306 | readonly writableEnded: boolean;
|
307 | readonly writableFinished: boolean;
|
308 | readonly writableCorked: number;
|
309 |
|
310 | _readableState: ReadableState;
|
311 |
|
312 | _read(size?: number): void;
|
313 | read(size?: number): any;
|
314 | setEncoding(enc: BufferEncoding): this;
|
315 | resume(): this;
|
316 | pause(): this;
|
317 | isPaused(): boolean;
|
318 | unpipe(dest?: Writable): this;
|
319 | unshift(chunk: any): boolean;
|
320 | wrap(oldStream: Readable): this;
|
321 | push(chunk: any, encoding?: BufferEncoding): boolean;
|
322 | map(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): Readable;
|
323 | filter(fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>, options?: ArrayOptions): Readable;
|
324 | forEach(fn: (data: any, options?: SignalOption) => void | Promise<void>, options?: ArrayOptions): Promise<void>;
|
325 | toArray(options?: SignalOption): Promise<any[]>;
|
326 | some(
|
327 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
328 | options?: ArrayOptions,
|
329 | ): Promise<boolean>;
|
330 | find<T>(fn: (data: any, options?: SignalOption) => data is T, options?: ArrayOptions): Promise<T | undefined>;
|
331 | find(
|
332 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
333 | options?: ArrayOptions,
|
334 | ): Promise<any>;
|
335 | every(
|
336 | fn: (data: any, options?: SignalOption) => boolean | Promise<boolean>,
|
337 | options?: ArrayOptions,
|
338 | ): Promise<boolean>;
|
339 | flatMap(fn: (data: any, options?: SignalOption) => any, options?: ArrayOptions): Readable;
|
340 | drop(limit: number, options?: SignalOption): Readable;
|
341 | take(limit: number, options?: SignalOption): Readable;
|
342 | asIndexedPairs(options?: SignalOption): Readable;
|
343 | reduce<T = any>(
|
344 | fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
345 | initial?: undefined,
|
346 | options?: Pick<ArrayOptions, "signal">,
|
347 | ): Promise<T>;
|
348 | reduce<T = any>(
|
349 | fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
|
350 | initial: T,
|
351 | options?: Pick<ArrayOptions, "signal">,
|
352 | ): Promise<T>;
|
353 | _destroy(err: Error | null, callback: (error: Error | null) => void): void;
|
354 | destroy(err?: Error, callback?: (error: Error | null) => void): this;
|
355 | pipe<S extends NodeJS.WritableStream>(dest: S, pipeOpts?: { end?: boolean | undefined }): S;
|
356 | addListener(ev: string | symbol, fn: (...args: any[]) => void): this;
|
357 | on(ev: string | symbol, fn: (...args: any[]) => void): this;
|
358 |
|
359 | _undestroy(): void;
|
360 | iterator(options?: { destroyOnReturn?: boolean }): AsyncIterableIterator<any>;
|
361 | [Symbol.asyncIterator](): AsyncIterableIterator<any>;
|
362 | // end-Readable
|
363 |
|
364 | constructor(options?: DuplexOptions);
|
365 | }
|
366 |
|
367 | // ==== _stream_passthrough ====
|
368 | class PassThrough extends Transform {
|
369 | constructor(options?: TransformOptions);
|
370 |
|
371 | _transform<T>(
|
372 | chunk: T,
|
373 | encoding: BufferEncoding | string | null | undefined,
|
374 | callback: (error?: Error, data?: T) => void,
|
375 | ): void;
|
376 | }
|
377 |
|
378 | // ==== _stream_readable ====
|
379 | interface ReadableStateOptions {
|
380 | defaultEncoding?: BufferEncoding | undefined;
|
381 | encoding?: BufferEncoding | undefined;
|
382 | highWaterMark?: number | undefined;
|
383 | objectMode?: boolean | undefined;
|
384 | readableObjectMode?: boolean | undefined;
|
385 | readableHighWaterMark?: number | undefined;
|
386 | }
|
387 |
|
388 | interface ReadableState {
|
389 | objectMode: boolean;
|
390 | highWaterMark: number;
|
391 | buffer: BufferList<any>;
|
392 | length: number;
|
393 | pipes: any;
|
394 | pipesCount: number;
|
395 | flowing: any;
|
396 | ended: boolean;
|
397 | endEmitted: boolean;
|
398 | reading: boolean;
|
399 | sync: boolean;
|
400 | needReadable: boolean;
|
401 | emittedReadable: boolean;
|
402 | readableListening: boolean;
|
403 | resumeScheduled: boolean;
|
404 | destroyed: boolean;
|
405 | awaitDrain: number;
|
406 | defaultEncoding: BufferEncoding;
|
407 | readingMore: boolean;
|
408 | decoder: StringDecoder | null;
|
409 | encoding: BufferEncoding | null;
|
410 |
|
411 | // new (options: ReadableStateOptions, stream: _Readable): ReadableState;
|
412 | }
|
413 |
|
414 | type ReadableOptions = ReadableStateOptions & {
|
415 | read?(this: _IReadable, size: number): void;
|
416 | destroy?(this: _IReadable, error: Error | null, callback: (error: Error | null) => void): void;
|
417 | };
|
418 |
|
419 | class Readable extends _Readable implements NodeJS.ReadableStream {
|
420 | readonly readableAborted: boolean;
|
421 | readonly readableDidRead: boolean;
|
422 | readonly readableEncoding: BufferEncoding | null;
|
423 | readonly readableEnded: boolean;
|
424 | readonly readableObjectMode: boolean;
|
425 |
|
426 | constructor(options?: ReadableOptions);
|
427 | pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
|
428 | compose<T extends NodeJS.ReadableStream>(
|
429 | stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>,
|
430 | options?: { signal: AbortSignal },
|
431 | ): T;
|
432 | }
|
433 |
|
434 | // ==== _stream_transform ====
|
435 | type TransformOptions = ReadableOptions & WritableOptions & {
|
436 | read?(this: _ITransform, size: number): void;
|
437 | write?(this: _ITransform, chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
438 | writev?(
|
439 | this: _ITransform,
|
440 | chunks: Array<{ chunk: any; encoding: BufferEncoding }>,
|
441 | callback: (error?: Error | null) => void,
|
442 | ): void;
|
443 | final?(this: _ITransform, callback: (error?: Error | null) => void): void;
|
444 | destroy?(this: _ITransform, error: Error | null, callback: (error: Error | null) => void): void;
|
445 | transform?(
|
446 | this: _ITransform,
|
447 | chunk: any,
|
448 | encoding: BufferEncoding,
|
449 | callback: (error?: Error | null, data?: any) => void,
|
450 | ): void;
|
451 | flush?(callback: (error?: Error | null, data?: any) => void): void;
|
452 | };
|
453 |
|
454 | interface _ITransform extends _IDuplex {
|
455 | _transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void;
|
456 | _flush(callback: (error?: Error | null, data?: any) => void): void;
|
457 | }
|
458 |
|
459 | class Transform extends Duplex {
|
460 | _transformState: {
|
461 | // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
|
462 | afterTransform: (this: Transform, er: any, data: any) => void | boolean;
|
463 | needTransform: boolean;
|
464 | transforming: boolean;
|
465 | writecb: ((err: any) => any) | null;
|
466 | writechunk: any; // TODO
|
467 | writeencoding: BufferEncoding | null;
|
468 | };
|
469 |
|
470 | constructor(options?: TransformOptions);
|
471 |
|
472 | _transform(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null, data?: any) => void): void;
|
473 | _flush(callback: (error?: Error | null, data?: any) => void): void;
|
474 | }
|
475 |
|
476 | // ==== _stream_writable ====
|
477 | interface CorkedRequest {
|
478 | next: any;
|
479 | entry: any;
|
480 | finish(): void;
|
481 | }
|
482 |
|
483 | interface BufferRequest {
|
484 | chunk: any; // TODO
|
485 | encoding: BufferEncoding;
|
486 | isBuf: boolean;
|
487 | callback: (error?: Error | null) => void;
|
488 | next: BufferRequest | null;
|
489 | }
|
490 |
|
491 | interface WritableStateOptions {
|
492 | decodeStrings?: boolean | undefined;
|
493 | defaultEncoding?: BufferEncoding | undefined;
|
494 | highWaterMark?: number | undefined;
|
495 | objectMode?: boolean | undefined;
|
496 | writableObjectMode?: boolean | undefined;
|
497 | writableHighWaterMark?: number | undefined;
|
498 | }
|
499 |
|
500 | interface WritableState {
|
501 | buffer: BufferRequest[];
|
502 | objectMode: boolean;
|
503 | highWaterMark: number;
|
504 | finalCalled: boolean;
|
505 | needDrain: boolean;
|
506 | ending: boolean;
|
507 | ended: boolean;
|
508 | finished: boolean;
|
509 | destroyed: boolean;
|
510 | decodeStrings: boolean;
|
511 | defaultEncoding: BufferEncoding;
|
512 | length: number;
|
513 | writing: boolean;
|
514 | corked: number;
|
515 | sync: boolean;
|
516 | bufferProcessing: boolean;
|
517 | writelen: number;
|
518 | pendingcb: number;
|
519 | prefinished: boolean;
|
520 | errorEmitted: boolean;
|
521 | bufferedRequestCount: number;
|
522 | writecb: ((err?: Error | null) => void) | null;
|
523 | onwrite: (er?: Error | null) => any;
|
524 | bufferedRequest: BufferRequest | null;
|
525 | lastBufferedRequest: BufferRequest | null;
|
526 | corkedRequestsFree: CorkedRequest;
|
527 |
|
528 |
|
529 |
|
530 | getBuffer(): BufferRequest[];
|
531 | }
|
532 |
|
533 | type WritableOptions = WritableStateOptions & {
|
534 | write?(
|
535 | this: _IWritable,
|
536 | chunk: any,
|
537 | encoding: BufferEncoding | string,
|
538 | callback: (error?: Error | null) => void,
|
539 | ): void;
|
540 | writev?(
|
541 | this: _IWritable,
|
542 | chunk: ArrayLike<{ chunk: any; encoding: BufferEncoding | string }>,
|
543 | callback: (error?: Error | null) => void,
|
544 | ): void;
|
545 | destroy?(this: _IWritable, error: Error | null, callback: (error?: Error | null) => void): void;
|
546 | final?(this: _IWritable, callback: (error?: Error | null) => void): void;
|
547 | };
|
548 |
|
549 | interface _IWritable extends _IEventEmitter {
|
550 | writable: boolean;
|
551 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
552 | write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
|
553 | end(cb?: () => void): this;
|
554 | end(data: string | Uint8Array, cb?: () => void): this;
|
555 | end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
|
556 | }
|
557 |
|
558 | class _Writable extends Stream implements _IWritable, NodeJS.WritableStream {
|
559 | writable: boolean;
|
560 | readonly writableHighWaterMark: number;
|
561 | readonly writableLength: number;
|
562 | readonly closed: boolean;
|
563 | readonly errored: Error | null;
|
564 | readonly writableNeedDrain: boolean;
|
565 | constructor(opts?: WritableOptions);
|
566 | _write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
567 | _writev?(chunks: Array<{ chunk: any; encoding: string }>, callback: (error?: Error | null) => void): void;
|
568 | _destroy(error: Error | null, callback: (error: Error | null) => void): void;
|
569 | _final(callback: (error?: Error | null) => void): void;
|
570 | write(chunk: any, cb?: (error: Error | null | undefined) => void): boolean;
|
571 | write(chunk: any, encoding?: string, cb?: (error: Error | null | undefined) => void): boolean;
|
572 | setDefaultEncoding(encoding: string): this;
|
573 | end(cb?: () => void): this;
|
574 | end(chunk: any, cb?: () => void): this;
|
575 | end(chunk: any, encoding?: string, cb?: () => void): this;
|
576 | cork(): void;
|
577 | uncork(): void;
|
578 | destroy(error?: Error): this;
|
579 |
|
580 | /**
|
581 | * Event emitter
|
582 | * The defined events on documents including:
|
583 | * 1. close
|
584 | * 2. drain
|
585 | * 3. error
|
586 | * 4. finish
|
587 | * 5. pipe
|
588 | * 6. unpipe
|
589 | */
|
590 | addListener(event: "close", listener: () => void): this;
|
591 | addListener(event: "drain", listener: () => void): this;
|
592 | addListener(event: "error", listener: (err: Error) => void): this;
|
593 | addListener(event: "finish", listener: () => void): this;
|
594 | addListener(event: "pipe", listener: (src: Readable) => void): this;
|
595 | addListener(event: "unpipe", listener: (src: Readable) => void): this;
|
596 | addListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
597 |
|
598 | emit(event: "close"): boolean;
|
599 | emit(event: "drain"): boolean;
|
600 | emit(event: "error", err: Error): boolean;
|
601 | emit(event: "finish"): boolean;
|
602 | emit(event: "pipe", src: Readable): boolean;
|
603 | emit(event: "unpipe", src: Readable): boolean;
|
604 | emit(event: string | symbol, ...args: any[]): boolean;
|
605 |
|
606 | on(event: "close", listener: () => void): this;
|
607 | on(event: "drain", listener: () => void): this;
|
608 | on(event: "error", listener: (err: Error) => void): this;
|
609 | on(event: "finish", listener: () => void): this;
|
610 | on(event: "pipe", listener: (src: Readable) => void): this;
|
611 | on(event: "unpipe", listener: (src: Readable) => void): this;
|
612 | on(event: string | symbol, listener: (...args: any[]) => void): this;
|
613 |
|
614 | once(event: "close", listener: () => void): this;
|
615 | once(event: "drain", listener: () => void): this;
|
616 | once(event: "error", listener: (err: Error) => void): this;
|
617 | once(event: "finish", listener: () => void): this;
|
618 | once(event: "pipe", listener: (src: Readable) => void): this;
|
619 | once(event: "unpipe", listener: (src: Readable) => void): this;
|
620 | once(event: string | symbol, listener: (...args: any[]) => void): this;
|
621 |
|
622 | prependListener(event: "close", listener: () => void): this;
|
623 | prependListener(event: "drain", listener: () => void): this;
|
624 | prependListener(event: "error", listener: (err: Error) => void): this;
|
625 | prependListener(event: "finish", listener: () => void): this;
|
626 | prependListener(event: "pipe", listener: (src: Readable) => void): this;
|
627 | prependListener(event: "unpipe", listener: (src: Readable) => void): this;
|
628 | prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
629 |
|
630 | prependOnceListener(event: "close", listener: () => void): this;
|
631 | prependOnceListener(event: "drain", listener: () => void): this;
|
632 | prependOnceListener(event: "error", listener: (err: Error) => void): this;
|
633 | prependOnceListener(event: "finish", listener: () => void): this;
|
634 | prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
|
635 | prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
|
636 | prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
637 |
|
638 | removeListener(event: "close", listener: () => void): this;
|
639 | removeListener(event: "drain", listener: () => void): this;
|
640 | removeListener(event: "error", listener: (err: Error) => void): this;
|
641 | removeListener(event: "finish", listener: () => void): this;
|
642 | removeListener(event: "pipe", listener: (src: Readable) => void): this;
|
643 | removeListener(event: "unpipe", listener: (src: Readable) => void): this;
|
644 | removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
|
645 |
|
646 | // static WritableState: WritableState;
|
647 | // private static realHasInstance: (obj: any) => boolean;
|
648 | destroyed: boolean;
|
649 | _writableState: WritableState;
|
650 |
|
651 | _undestroy(): void;
|
652 | }
|
653 |
|
654 | class Writable extends _Writable {
|
655 | readonly writableEnded: boolean;
|
656 | readonly writableFinished: boolean;
|
657 | readonly writableObjectMode: boolean;
|
658 | readonly writableCorked: number;
|
659 |
|
660 | constructor(opts?: WritableOptions);
|
661 | }
|
662 |
|
663 | class Stream extends _Readable {
|
664 | constructor(options?: ReadableOptions);
|
665 | pipe<T extends NodeJS.WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
|
666 | compose<T extends NodeJS.ReadableStream>(
|
667 | stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>,
|
668 | options?: { signal: AbortSignal },
|
669 | ): T;
|
670 | }
|
671 |
|
672 | const finished: typeof NodeStream.finished;
|
673 | const pipeline: typeof NodeStream.pipeline;
|
674 | }
|
675 |
|
676 | export = _Readable;
|
677 | export as namespace _Readable;
|