UNPKG

1.67 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import { Stream } from "stream";
4
5type Appendable = NodeJS.ReadableStream | NodeJS.WritableStream | Buffer | string | NextFunction;
6type NextFunction = (next: (stream: Appendable) => any) => any;
7
8interface Options {
9 maxDataSize?: number | undefined;
10 pauseStreams?: boolean | undefined;
11}
12
13declare class CombinedStream extends Stream implements Options {
14 readonly writable: boolean;
15 readonly readable: boolean;
16 readonly dataSize: number;
17 maxDataSize: number;
18 pauseStreams: boolean;
19 append(stream: Appendable): this;
20 write(data: any): void;
21 pause(): void;
22 resume(): void;
23 end(): void;
24 destroy(): void;
25
26 // private properties
27 _released: boolean;
28 // @TODO it should be a type of Array<'delayed-stream' instance | Buffer | string>
29 _streams: Array<Stream | Buffer | string>;
30 _currentStream: Stream | Buffer | string | null;
31 _getNext(): void;
32 _pipeNext(): void;
33 _handleErrors(stream: NodeJS.EventEmitter): void;
34 _reset(): void;
35 _checkDataSize(): void;
36 _updateDataSize(): void;
37 _emitError(error: Error): void;
38
39 // events
40 on(event: "close" | "end" | "resume" | "pause", cb: () => void): this;
41 on(event: "error", cb: (err: Error) => void): this;
42 on(event: "data", cb: (data: any) => void): this;
43 once(event: "close" | "end" | "resume" | "pause", cb: () => void): this;
44 once(event: "error", cb: (err: Error) => void): this;
45 once(event: "data", cb: (data: any) => void): this;
46
47 static create(options?: Options): CombinedStream;
48 static isStreamLike(stream: any): stream is Stream;
49}
50
51export = CombinedStream;