stream/iter 模块
🌐 The stream/iter module
大多数函数既可以作为命名导出使用,也可以作为 Stream 命名空间对象的属性使用。经典的流适配器(fromReadable()、fromWritable()、toReadable()、toReadableSync() 和 toWritable())以及静态辅助对象(Broadcast、Share 和 SyncShare)只能作为命名导出使用。
🌐 Most functions are available both as named exports and as properties of the
Stream namespace object. The classic stream adapters (fromReadable(),
fromWritable(), toReadable(), toReadableSync(), and toWritable()) and
the static helper objects (Broadcast, Share, and SyncShare) are named
exports only.
// Named exports
import { from, pull, bytes, Stream } from 'node:stream/iter';
// Namespace access
Stream.from('hello'); 由 Iterable Streams API 定义的选项字典使用 Web IDL 转换语义。null 会被当作空字典处理,未知的成员会被忽略,已知成员会在操作运行前转换为它们声明的类型。转换失败会使用 Node.js 错误码,例如 ERR_INVALID_ARG_TYPE、ERR_INVALID_ARG_VALUE 和 ERR_OUT_OF_RANGE。
🌐 Options dictionaries defined by the Iterable Streams API use Web IDL
conversion semantics. null is treated as an empty dictionary, unknown
members are ignored, and known members are converted to their declared types
before the operation runs. Conversion failures use Node.js error codes such as
ERR_INVALID_ARG_TYPE, ERR_INVALID_ARG_VALUE, and ERR_OUT_OF_RANGE.
// Named exports
const { from, pull, bytes, Stream } = require('node:stream/iter');
// Namespace access
Stream.from('hello'); 在模块说明符中包含 node: 前缀是可选的。
🌐 Including the node: prefix on the module specifier is optional.