Skip to content

stream: pipeTo treats writer transform() method as pipeline transform #63683

@trivikr

Description

@trivikr

Version

26.2.0

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

import { pipeTo, from } from 'node:stream/iter';

const chunks = [];

const writer = {
  transform() {
    console.log('BUG: writer.transform() was called');
    return null;
  },
  write(chunk) {
    chunks.push(new TextDecoder().decode(chunk));
  },
};

await pipeTo(from('hello'), writer);

console.log(chunks.join(''));

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

hello

The final pipeTo() argument should be treated only as the destination writer; transform objects are only the arguments before the writer.

What do you see instead?

BUG: writer.transform() was called
node:internal/streams/iter/pull:584
  for await (const item of output) {
                           ^

TypeError: Cannot read properties of null (reading 'Symbol(Symbol.asyncIterator)')
    at applyStatefulAsyncTransform (node:internal/streams/iter/pull:584:28)
    at applyStatefulAsyncTransform.next (<anonymous>)
    at createAsyncPipeline (node:internal/streams/iter/pull:703:22)
    at createAsyncPipeline.next (<anonymous>)
    at pipeTo (node:internal/streams/iter/pull:1000:26)
    at file:///Users/trivikram/workspace/test-repro/repro.js:15:7
    at ModuleJob.run (node:internal/modules/esm/module_job:439:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async node:internal/modules/esm/loader:646:26
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)

pipeTo() calls writer.transform() when the destination writer object also has a transform() method, so the writer is treated as a transform as well as the destination.

Additional information

No response

Metadata

Metadata

Assignees

Labels

streamIssues and PRs related to the stream subsystem.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions