[duplexer3] introduce typings (#18337)

This commit is contained in:
Dimitri Benin
2017-07-24 11:47:26 -07:00
committed by Andy
parent 7353fa8519
commit 7e42c2db56
4 changed files with 88 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
import * as stream from 'stream';
import duplexer3 = require('duplexer3');
const writable = new stream.Writable({objectMode: true});
const readable = new stream.Readable({objectMode: true});
writable._write = (input, encoding, done) => {
if (readable.push(input)) {
return done();
} else {
readable.once('drain', <(...args: any[]) => void> done);
}
};
readable._read = n => {
// no-op
};
// simulate the readable thing closing after a bit
writable.once('finish', () => {
setTimeout(() => {
readable.push(null);
}, 500);
});
const duplex = duplexer3(writable, readable);
const duplex2 = duplexer3({bubbleErrors: true, allowHalfOpen: true}, writable, readable);
duplex.on('data', e => {
console.log('got data', JSON.stringify(e));
});
duplex.on('finish', () => {
console.log('got finish event');
});
duplex.on('end', () => {
console.log('got end event');
});
duplex.write('oh, hi there', () => {
console.log('finished writing');
});
duplex.end(() => {
console.log('finished ending');
});
+18
View File
@@ -0,0 +1,18 @@
// Type definitions for duplexer3 0.1
// Project: https://github.com/floatdrop/duplexer3
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference types="node" />
import * as stream from 'stream';
export = duplexer3;
declare function duplexer3(writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
declare function duplexer3(options: duplexer3.Options, writableStream: NodeJS.WritableStream, readableStream: NodeJS.ReadableStream): stream.Duplex;
declare namespace duplexer3 {
interface Options extends stream.DuplexOptions {
bubbleErrors?: boolean;
}
}
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"duplexer3-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }