From 4d27d802e67c4a11e6fbdd3d020b1209daa0dc3f Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Sun, 5 Jul 2026 10:04:44 +0200 Subject: [PATCH] stream: expose ReadableStreamTee Signed-off-by: Matteo Collina PR-URL: https://github.com/nodejs/node/pull/64195 Refs: https://github.com/nodejs/undici/issues/5358 Reviewed-By: Matthew Aitken Reviewed-By: James M Snell --- doc/api/webstreams.md | 22 ++++++++++++++++++++ lib/stream/web.js | 21 +++++++++++++++++++ test/parallel/test-whatwg-readablestream.js | 23 +++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/doc/api/webstreams.md b/doc/api/webstreams.md index 55b27584361e1c..263106b5d9e74a 100644 --- a/doc/api/webstreams.md +++ b/doc/api/webstreams.md @@ -106,6 +106,28 @@ For more details refer to the relevant documentation: ## API +### `ReadableStreamTee(stream[, cloneForBranch2])` + + + +> Stability: 1 - Experimental + +* `stream` {ReadableStream} +* `cloneForBranch2` {boolean} When `true`, chunks enqueued into the second + branch are cloned from chunks enqueued into the first branch. **Default:** + `false`. +* Returns: {ReadableStream\[]} Two {ReadableStream} branches. + +Runs the WHATWG `ReadableStreamTee` abstract operation on `stream`. + +This differs from `readableStream.tee()` only when `cloneForBranch2` is +`true`. The `tee()` method always passes `false`, while other web platform +specifications, such as Fetch body cloning, pass `true` so that the second +branch receives cloned chunks and consumption of one branch cannot mutate chunks +seen by the other. + ### Class: `ReadableStream`