UNPKG

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