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

# 读取文件为 Buffer

`Bun.file()` 函数接受一个路径并返回 `BunFile` 实例。`BunFile` 继承自 `Blob`，因此你可以以多种格式惰性读取文件。

要将文件读取为 `Buffer`，先用 `.arrayBuffer()` 将其读取为 `ArrayBuffer`，然后将结果传递给 `Buffer.from()`。

```ts index.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
const path = "/path/to/package.json";
const file = Bun.file(path);

const arrbuf = await file.arrayBuffer();
const buffer = Buffer.from(arrbuf);
```

***

参见 [Buffer](/runtime/binary-data#buffer) 了解如何在 Bun 中使用 `Buffer` 和其他二进制数据格式。
