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