UNPKG

1.92 kBTypeScriptView Raw
1// Type definitions for through2 v 2.0
2// Project: https://github.com/rvagg/through2
3// Definitions by: Bart van der Schoor <https://github.com/Bartvds>,
4// jedmao <https://github.com/jedmao>,
5// Georgios Valotasios <https://github.com/valotas>,
6// Ben Chauvette < https://github.com/bdchauvette>,
7// TeamworkGuy2 <https://github.com/TeamworkGuy2>,
8// Alorel <https://github.com/Alorel>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
11/// <reference types="node" />
12
13import stream = require('stream');
14
15declare function through2(transform?: through2.TransformFunction, flush?: through2.FlushCallback): stream.Transform;
16declare function through2(opts?: stream.DuplexOptions, transform?: through2.TransformFunction, flush?: through2.FlushCallback): stream.Transform;
17
18declare namespace through2 {
19 interface Through2Constructor extends stream.Transform {
20 new (opts?: stream.DuplexOptions): stream.Transform;
21 (opts?: stream.DuplexOptions): stream.Transform;
22 }
23
24 type TransformCallback = (err?: any, data?: any) => void;
25 type TransformFunction = (this: stream.Transform, chunk: any, enc: BufferEncoding, callback: TransformCallback) => void;
26 type FlushCallback = (this: stream.Transform, flushCallback: () => void) => void;
27
28 /**
29 * Convenvience method for creating object streams
30 */
31 function obj(transform?: TransformFunction, flush?: FlushCallback): stream.Transform;
32
33 /**
34 * Creates a constructor for a custom Transform. This is useful when you
35 * want to use the same transform logic in multiple instances.
36 */
37 function ctor(transform?: TransformFunction, flush?: FlushCallback): Through2Constructor;
38 function ctor(opts?: stream.DuplexOptions, transform?: TransformFunction, flush?: FlushCallback): Through2Constructor;
39}
40
41export = through2;