Skip to content

stream/iter: Broadcast.from() does not normalize byte inputs like from() #64081

Description

@trivikr

Version

main

Platform

macOS 26.5.0

Subsystem

stream

What steps will reproduce the bug?

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

async function readBroadcast(input) {
  const { broadcast } = Broadcast.from(input);
  return await text(broadcast.push());
}

async function show(label, input) {
  try {
    const data = await readBroadcast(input);
    console.log(`${label}: ok ${JSON.stringify(data)}`);
  } catch (error) {
    console.log(`${label}: ${error.code ?? error.name}: ${error.message}`);
  }
}

await show("Broadcast.from(['abc'])", ['abc']);
await show("Broadcast.from('abc')", 'abc');
await show('Broadcast.from(new Uint8Array([97]))', new Uint8Array([97]));

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

Always

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

Broadcast.from(['abc']): ok "abc"
Broadcast.from('abc'): ok "abc"
Broadcast.from(new Uint8Array([97])): ok "a"

Broadcast.from() to normalize byte inputs consistently with from(), so strings and Uint8Array inputs broadcast as byte chunks.

What do you see instead?

Broadcast.from(['abc']): ok "abc"
Broadcast.from('abc'): ERR_INVALID_ARG_TYPE: The "input" argument must be an instance of Broadcastable, AsyncIterable, or Iterable. Received type string ('abc')
Broadcast.from(new Uint8Array([97])): ERR_INVALID_ARG_TYPE: The "chunk" argument must be of type string or an instance of Uint8Array. Received type number (97)

Broadcast.from(['abc']) broadcasts "abc", but Broadcast.from('abc') rejects the string input and Broadcast.from(new Uint8Array([97])) iterates the byte values and fails on 97

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