mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 09:01:45 +08:00
* [through2] Fix typos * [through2] Change return types to stream.Transform `through2` creates `stream.Transform`-flavored streams, so switching the return types to `stream.Transform` gives us richer typing information than using `NodeJS.ReadWriteStream`, which is missing methods (e.g. `stream.Transform#push`) and the ability to use object mode. * [through2] Add through2.ctor method * [through2] Update header and docs
103 lines
2.1 KiB
TypeScript
103 lines
2.1 KiB
TypeScript
/// <reference path="./through2.d.ts" />
|
|
/// <reference path="../node/node.d.ts" />
|
|
|
|
import stream = require('stream');
|
|
import through2 = require('through2');
|
|
|
|
var rws: stream.Transform;
|
|
var Rws: through2.Through2Constructor;
|
|
|
|
rws = through2({
|
|
objectMode: true,
|
|
allowHalfOpen: true
|
|
}, function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
}, () => {
|
|
|
|
});
|
|
|
|
rws = through2(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
}, () => {
|
|
|
|
});
|
|
|
|
rws = through2(function (entry: any, enc: string, callback: (error: any, data?: any) => void) {
|
|
callback(null, 'foo');
|
|
}, (flushCallback: () => void) => {
|
|
flushCallback();
|
|
});
|
|
|
|
rws = through2(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
});
|
|
|
|
rws = through2();
|
|
|
|
// obj
|
|
rws = through2.obj(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
}, () => {
|
|
|
|
});
|
|
|
|
rws = through2.obj(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
});
|
|
|
|
rws = through2.obj(function (entry: any, enc: string, callback: (err: any) => void) {
|
|
callback('Oups!');
|
|
}, (flashCallback) => {
|
|
flashCallback();
|
|
});
|
|
|
|
// ctor
|
|
Rws = through2.ctor({
|
|
objectMode: true,
|
|
allowHalfOpen: true
|
|
}, function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
}, () => {
|
|
|
|
});
|
|
|
|
rws = Rws();
|
|
rws = new Rws();
|
|
rws = new Rws({ objectMode: true, allowHalfOpen: true });
|
|
|
|
Rws = through2.ctor(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
}, () => {
|
|
|
|
});
|
|
|
|
rws = Rws();
|
|
rws = new Rws();
|
|
rws = new Rws({ objectMode: true, allowHalfOpen: true });
|
|
|
|
Rws = through2.ctor(function (entry: any, enc: string, callback: (error: any, data?: any) => void) {
|
|
callback(null, 'foo');
|
|
}, (flushCallback: () => void) => {
|
|
flushCallback();
|
|
});
|
|
|
|
rws = Rws();
|
|
rws = new Rws();
|
|
rws = new Rws({ objectMode: true, allowHalfOpen: true });
|
|
|
|
Rws = through2.ctor(function (entry: any, enc: string, callback: () => void) {
|
|
this.push('foo');
|
|
callback();
|
|
});
|
|
|
|
rws = Rws();
|
|
rws = new Rws();
|
|
rws = new Rws({ objectMode: true, allowHalfOpen: true });
|