Skip to content

stream.pipeline does not accept 'Buffer' as a valid first argument, even though it is an Iterable #37731

@carlansley

Description

@carlansley
  • v15.11.0
  • Darwin mbp16.local 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
  • stream

What steps will reproduce the bug?

This issue is a continuation of #36437. Although Iterables are now supported, Buffer (which is an Iterable) is not.

const stream = require("stream");

async function main() {
    await stream.pipeline(
        /*stream1*/ Buffer.from('abc'),
        /*stream2*/ new stream.PassThrough({ objectMode: true }),
        /*callback*/ () => { console.log("done"); });
}

main().catch(e => console.error(e));

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

Reproduces in all versions of Node tested, 14.15.5+.

What is the expected behavior?

For Buffer to be able to be used as a source/first argument. Note if Buffer.from('abc') is changed to Buffer.from('abc').values(), it behaves correctly.

What do you see instead?

> TypeError: stream.on is not a function
    at destroyer (node:internal/streams/pipeline:39:10)
    at Function.pipeline (node:internal/streams/pipeline:175:21)
    at main (REPL8:2:18)
    at REPL10:1:1
    at Script.runInThisContext (node:vm:131:12)
    at REPLServer.defaultEval (node:repl:522:29)
    at bound (node:domain:416:15)
    at REPLServer.runBound [as eval] (node:domain:427:12)
    at REPLServer.onLine (node:repl:844:10)
    at REPLServer.emit (node:events:390:22)

Additional information

Metadata

Metadata

Assignees

No one assigned

    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