readableStream.values([options])


创建并返回一个异步迭代器,可用于消费此 ReadableStream 的数据。

【Creates and returns an async iterator usable for consuming this ReadableStream's data.】

在异步迭代器处于活动状态时,会导致 readableStream.lockedtrue

【Causes the readableStream.locked to be true while the async iterator is active.】

import { Buffer } from 'node:buffer';

const stream = new ReadableStream(getSomeSource());

for await (const chunk of stream.values({ preventCancel: true }))
  console.log(Buffer.from(chunk).toString());