UNPKG

1.47 kBTypeScriptView Raw
1/// <reference types="node" />
2
3import stream = require("stream");
4
5declare function through2(transform?: through2.TransformFunction, flush?: through2.FlushCallback): stream.Transform;
6declare function through2(
7 opts?: stream.DuplexOptions,
8 transform?: through2.TransformFunction,
9 flush?: through2.FlushCallback,
10): stream.Transform;
11
12declare namespace through2 {
13 interface Through2Constructor extends stream.Transform {
14 new(opts?: stream.DuplexOptions): stream.Transform;
15 (opts?: stream.DuplexOptions): stream.Transform;
16 }
17
18 type TransformCallback = (err?: any, data?: any) => void;
19 type TransformFunction = (
20 this: stream.Transform,
21 chunk: any,
22 enc: BufferEncoding,
23 callback: TransformCallback,
24 ) => void;
25 type FlushCallback = (this: stream.Transform, flushCallback: () => void) => void;
26
27 /**
28 * Convenvience method for creating object streams
29 */
30 function obj(transform?: TransformFunction, flush?: FlushCallback): stream.Transform;
31
32 /**
33 * Creates a constructor for a custom Transform. This is useful when you
34 * want to use the same transform logic in multiple instances.
35 */
36 function ctor(transform?: TransformFunction, flush?: FlushCallback): Through2Constructor;
37 function ctor(
38 opts?: stream.DuplexOptions,
39 transform?: TransformFunction,
40 flush?: FlushCallback,
41 ): Through2Constructor;
42}
43
44export = through2;