stream[Symbol.asyncIterator]()


该流实现了 Symbol.asyncIterator,使其可以直接用于 for await...of 循环。每次迭代都会生成一批 Uint8Array 块。

🌐 The stream implements Symbol.asyncIterator, making it directly usable in for await...of loops. Each iteration yields a batch of Uint8Array chunks.

每个流只能获取一个异步迭代器。第二次调用会抛出 ERR_INVALID_STATE。不可读的流(仅出站的单向流或已关闭流)会返回一个立即完成的迭代器。

🌐 Only one async iterator can be obtained per stream. A second call throws ERR_INVALID_STATE. Non-readable streams (outbound-only unidirectional or closed) return an immediately-finished iterator.

for await (const chunks of stream) {
  for (const chunk of chunks) {
    // Process each Uint8Array chunk
  }
} 

与流/迭代工具兼容:

🌐 Compatible with stream/iter utilities:

import Stream from 'node:stream/iter';
const body = await Stream.bytes(stream);
const text = await Stream.text(stream);
await Stream.pipeTo(stream, someWriter);