mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
As documented in https://www.npmjs.com/package/duplexer2#duplexer2-1, options should not only be the duplexer2-specific `bubbleErrors` option, but also regular stream.Duplex options.
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
import stream = require("stream");
|
|
import duplexer2 = require("duplexer2");
|
|
|
|
const writable = new stream.Writable({ objectMode: true });
|
|
const readable = new stream.Readable({ objectMode: true });
|
|
|
|
writable.once("finish", () => {
|
|
setTimeout(() => {
|
|
readable.push(null);
|
|
}, 500);
|
|
});
|
|
|
|
const duplex = duplexer2(writable, readable);
|
|
|
|
duplex.on("data", (e: any) => {
|
|
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");
|
|
});
|
|
|
|
const duplexWithOptions = duplexer2({ readableObjectMode: true, writableObjectMode: true }, writable, readable);
|
|
|
|
duplexWithOptions.on("data", (e: any) => {
|
|
console.log("got data", JSON.stringify(e));
|
|
});
|
|
|
|
duplexWithOptions.on("finish", () => {
|
|
console.log("got finish event");
|
|
});
|
|
|
|
duplexWithOptions.on("end", () => {
|
|
console.log("got end event");
|
|
});
|
|
|
|
duplexWithOptions.write("oh, hi there", () => {
|
|
console.log("finished writing");
|
|
});
|
|
|
|
duplexWithOptions.end("", () => {
|
|
console.log("finished ending");
|
|
});
|