Bun.file()
函式接受路徑並傳回 BunFile
實例。BunFile
類別擴充 Blob
,並允許您以各種格式延遲讀取檔案。使用 .stream()
以 ReadableStream
遞增使用檔案。
const path = "/path/to/package.json";
const file = Bun.file(path);
const stream = file.stream();
串流的區塊可以使用 for await
作為 非同步 iterable 使用。
for await (const chunk of stream) {
chunk; // => Uint8Array
}
參閱 串流 文件,以取得有關在 Bun 中使用串流的更多資訊。