Bun.file() 函数接受一个路径并返回一个 BunFile 实例。BunFile 类扩展了 Blob,允许你以多种格式延迟读取文件。使用 .stream() 将文件作为 ReadableStream 增量消费。
ts
const path = "/path/to/package.json";
const file = Bun.file(path);
const stream = file.stream();可以使用 for await 将流的块作为 异步可迭代对象 消费。
ts
for await (const chunk of stream) {
chunk; // => Uint8Array
}请参阅 流 文档,了解在 Bun 中使用流的更多信息。