mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-12-04 20:21:46 +00:00
[duplexer3] introduce typings (#18337)
This commit is contained in:
@@ -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');
|
||||
});
|
||||
Vendored
+18
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user