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 中使用流的更多信息。