From 3a1c6aeeb4f5062a5ca3f50f64add68e4877f5a4 Mon Sep 17 00:00:00 2001 From: Erick Wendel Date: Thu, 14 Apr 2022 10:53:37 -0300 Subject: [PATCH 1/5] doc,test: add tests and docs for duplex.fromWeb and duplex.toWeb --- doc/api/stream.md | 54 +++++++++++++++++++ test/parallel/test-stream-duplex.js | 80 ++++++++++++++++++++++++++++- 2 files changed, 133 insertions(+), 1 deletion(-) diff --git a/doc/api/stream.md b/doc/api/stream.md index d59cd6b51629e4..25ed69ce97e94f 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2874,6 +2874,38 @@ added: v17.0.0 * `signal` {AbortSignal} * Returns: {stream.Duplex} +```mjs +import { Duplex } from 'stream'; +import { + ReadableStream, + WritableStream +} from 'stream/web'; + +const readable = new ReadableStream({ + start(controller) { + controller.enqueue('world'); + }, +}); + +const writable = new WritableStream({ + write(chunk) { + console.log('writable', chunk); + } +}); + +const pair = { + readable, + writable +}; +const duplex = Duplex.fromWeb(pair, { encoding: 'utf8', objectMode: true }); + +duplex.write('hello'); + +for await (const chunk of duplex) { + console.log('readable', chunk); +} +``` + ### `stream.Duplex.toWeb(streamDuplex)`