From 7a89e5ccda8460fcee48793db5c31d4af9a483eb Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Sun, 31 May 2026 12:39:56 -0700 Subject: [PATCH] stream: remove transform-writer handling in pipeTo The pipeTo() and pipeToSync() argument parser already requires the destination argument to be a writer. Remove the later transform-writer handling so writer objects with a transform() method are treated only as destinations. Fixes: https://github.com/nodejs/node/issues/63683 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 --- lib/internal/streams/iter/pull.js | 10 --------- test/parallel/test-stream-iter-pipeto.js | 27 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/internal/streams/iter/pull.js b/lib/internal/streams/iter/pull.js index 95871e99037d58..1355911f1ff56e 100644 --- a/lib/internal/streams/iter/pull.js +++ b/lib/internal/streams/iter/pull.js @@ -794,11 +794,6 @@ function pull(source, ...args) { function pipeToSync(source, ...args) { const { transforms, writer, options } = parsePipeToArgs(args, 'writeSync'); - // Handle transform-writer - if (isTransformObject(writer)) { - ArrayPrototypePush(transforms, writer); - } - // Normalize source and create pipeline const normalized = fromSync(source); const pipeline = transforms.length > 0 ? @@ -852,11 +847,6 @@ async function pipeTo(source, ...args) { validateAbortSignal(options.signal, 'options.signal'); } - // Handle transform-writer - if (isTransformObject(writer)) { - ArrayPrototypePush(transforms, writer); - } - const signal = options?.signal; // Check for abort diff --git a/test/parallel/test-stream-iter-pipeto.js b/test/parallel/test-stream-iter-pipeto.js index bc6fa9d4984233..5d8b5088f54089 100644 --- a/test/parallel/test-stream-iter-pipeto.js +++ b/test/parallel/test-stream-iter-pipeto.js @@ -141,6 +141,31 @@ async function testPipeToSyncWithTransforms() { assert.strictEqual(chunks.join(''), 'HELLO'); } +async function testPipeToWriterTransformMethodIgnored() { + const chunks = []; + const writer = { + transform: common.mustNotCall(), + write(chunk) { chunks.push(new TextDecoder().decode(chunk)); }, + }; + + await pipeTo(from('hello'), writer); + assert.strictEqual(chunks.join(''), 'hello'); +} + +async function testPipeToSyncWriterTransformMethodIgnored() { + const chunks = []; + const writer = { + transform: common.mustNotCall(), + writeSync(chunk) { + chunks.push(new TextDecoder().decode(chunk)); + return true; + }, + }; + + pipeToSync(fromSync('hello'), writer); + assert.strictEqual(chunks.join(''), 'hello'); +} + // PipeTo with writev writer async function testPipeToWithWritevWriter() { const allChunks = []; @@ -301,6 +326,8 @@ Promise.all([ testPipeToWithSignal(), testPipeToWithTransforms(), testPipeToSyncWithTransforms(), + testPipeToWriterTransformMethodIgnored(), + testPipeToSyncWriterTransformMethodIgnored(), testPipeToWithWritevWriter(), testPipeToSyncFallback(), testPipeToPreventFail(),