From 155b677dc96bee42e61a74c494597b3377ee6481 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 23 Jun 2021 22:24:19 -0700 Subject: [PATCH] stream: implement streams to webstreams adapters Experimental adapters for the webstreams API Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/39134 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina --- doc/api/stream.md | 68 +- lib/internal/fs/promises.js | 2 + lib/internal/streams/duplex.js | 19 + lib/internal/streams/readable.js | 19 + lib/internal/streams/writable.js | 19 + lib/internal/webstreams/adapters.js | 921 ++++++++++++++++++ ...t-whatwg-webstreams-adapters-streambase.js | 67 ++ ...g-webstreams-adapters-to-readablestream.js | 204 ++++ ...treams-adapters-to-readablewritablepair.js | 250 +++++ ...twg-webstreams-adapters-to-streamduplex.js | 149 +++ ...g-webstreams-adapters-to-streamreadable.js | 229 +++++ ...g-webstreams-adapters-to-streamwritable.js | 231 +++++ ...g-webstreams-adapters-to-writablestream.js | 167 ++++ 13 files changed, 2344 insertions(+), 1 deletion(-) create mode 100644 lib/internal/webstreams/adapters.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-streambase.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-readablestream.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-readablewritablepair.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-streamduplex.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-streamreadable.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-streamwritable.js create mode 100644 test/parallel/test-whatwg-webstreams-adapters-to-writablestream.js diff --git a/doc/api/stream.md b/doc/api/stream.md index 96f0650ac07f13..b16c5e3bd0f707 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -2080,7 +2080,7 @@ for performance reasons. ### `stream.Readable.fromWeb(readableStream[, options])` > Stability: 1 - Experimental @@ -2093,6 +2093,41 @@ added: v16.11.0 * `signal` {AbortSignal} * Returns: {stream.Readable} +### `stream.Readable.toWeb(streamReadable)` + + +> Stability: 1 - Experimental + +* `streamReadable` {stream.Readable} +* Returns: {ReadableStream} + +### `stream.Writable.fromWeb(writableStream[, options])` + + +> Stability: 1 - Experimental + +* `writableStream` {WritableStream} +* `options` {Object} + * `decodeStrings` {boolean} + * `highWaterMark` {number} + * `objectMode` {boolean} + * `signal` {AbortSignal} +* Returns: {stream.Writable} + +### `stream.Writable.toWeb(streamWritable)` + + +> Stability: 1 - Experimental + +* `streamWritable` {stream.Writable} +* Returns: {WritableStream} + ### `stream.Readable.isDisturbed(stream)` + +> Stability: 1 - Experimental + +* `pair` {Object} + * `readable` {ReadableStream} + * `writable` {WritableStream} +* `options` {Object} + * `allowHalfOpen` {boolean} + * `decodeStrings` {boolean} + * `encoding` {string} + * `highWaterMark` {number} + * `objectMode` {boolean} + * `signal` {AbortSignal} +* Returns: {stream.Duplex} + +### `stream.Duplex.toWeb(streamDuplex)` + + +> Stability: 1 - Experimental + +* `streamDuplex` {stream.Duplex} +* Returns: {Object} + * `readable` {ReadableStream} + * `writable` {WritableStream} + ### `stream.addAbortSignal(signal, stream)`