MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1declare module 'stream' {
2 class Stream {
3 pipe<T extends Writable>(destination: T, options?: { end?: boolean }): T;
4 unpipe(destination?: Writable): this;
5 pause(): this;
6 resume(): this;
7 isPaused(): boolean;
8 destroy(error?: Error): this;
9 on(event: string, listener: (...args: unknown[]) => void): this;
10 once(event: string, listener: (...args: unknown[]) => void): this;
11 off(event: string, listener: (...args: unknown[]) => void): this;
12 removeListener(event: string, listener: (...args: unknown[]) => void): this;
13 removeAllListeners(event?: string): this;
14 }
15
16 class Readable extends Stream {
17 constructor(options?: Record<string, unknown>);
18 _read(size?: number): void;
19 read(size?: number): Uint8Array | string | null;
20 push(chunk: Uint8Array | string | null): boolean;
21 setEncoding(encoding?: string): this;
22 on(event: 'data', listener: (chunk: Uint8Array | string) => void): this;
23 on(event: 'end' | 'close' | 'readable', listener: () => void): this;
24 on(event: 'error', listener: (error: Error) => void): this;
25 on(event: string, listener: (...args: unknown[]) => void): this;
26 static from(source: unknown, options?: Record<string, unknown>): Readable;
27 static fromWeb(source: unknown, options?: Record<string, unknown>): Readable;
28 }
29
30 class Writable extends Stream {
31 constructor(options?: Record<string, unknown>);
32 _write(chunk: Uint8Array | string, encoding: string, callback: (error?: Error | null) => void): void;
33 write(chunk: Uint8Array | string, encoding?: string, callback?: (error?: Error | null) => void): boolean;
34 end(chunk?: Uint8Array | string, encoding?: string, callback?: (error?: Error | null) => void): this;
35 cork(): void;
36 uncork(): void;
37 on(event: 'drain' | 'finish' | 'close', listener: () => void): this;
38 on(event: 'error', listener: (error: Error) => void): this;
39 on(event: string, listener: (...args: unknown[]) => void): this;
40 }
41
42 class Duplex extends Readable {
43 constructor(options?: Record<string, unknown>);
44 write(chunk: Uint8Array | string, encoding?: string, callback?: (error?: Error | null) => void): boolean;
45 end(chunk?: Uint8Array | string, encoding?: string, callback?: (error?: Error | null) => void): this;
46 cork(): void;
47 uncork(): void;
48 }
49
50 class Transform extends Duplex {
51 constructor(options?: Record<string, unknown>);
52 }
53
54 class PassThrough extends Transform {
55 constructor(options?: Record<string, unknown>);
56 }
57
58 function pipeline(...streams: Array<Stream | ((error?: Error | null) => void)>): Stream;
59 function finished(stream: Stream, callback?: (error?: Error | null) => void): Stream;
60 function getDefaultHighWaterMark(objectMode: boolean): number;
61 function setDefaultHighWaterMark(objectMode: boolean, value: number): void;
62
63 const promises: {
64 pipeline(...streams: Stream[]): Promise<void>;
65 finished(stream: Stream): Promise<void>;
66 };
67
68 export default Stream;
69 export {
70 Stream,
71 Readable,
72 Writable,
73 Duplex,
74 Transform,
75 PassThrough,
76 pipeline,
77 finished,
78 getDefaultHighWaterMark,
79 setDefaultHighWaterMark,
80 promises
81 };
82}
83
84declare module 'ant:stream' {
85 export * from 'stream';
86 export { default } from 'stream';
87}
88
89declare module 'node:stream' {
90 export * from 'stream';
91 export { default } from 'stream';
92}