> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 以 ReadableStream 读取文件

`Bun.file()` 函数接受一个路径并返回一个 `BunFile` 实例。`BunFile` 类继承自 `Blob`，允许你以多种格式懒加载地读取文件。使用 `.stream()` 可以将文件作为 `ReadableStream` 逐步消费。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const path = "/path/to/package.json";
const file = Bun.file(path);

const stream = file.stream();
```

***

可将流的块作为 [异步可迭代对象](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) 使用 `for await` 进行消费。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
for await (const chunk of stream) {
  chunk; // => Uint8Array
}
```

***

有关在 Bun 中使用流的更多信息，请参阅[Streams](/runtime/streams)文档。
