> ## 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.

# 读取文件到 Buffer

`Bun.file()` 函数接受一个路径并返回一个 `BunFile` 实例。`BunFile` 类继承自 `Blob`，允许你以多种格式懒加载读取文件。

要将文件读取到一个 `Buffer` 实例，首先使用 `.arrayBuffer()` 将文件作为 `ArrayBuffer` 读取，然后用 `Buffer.from()` 从该 `ArrayBuffer` 创建一个 `Buffer`。

```ts index.ts icon="https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217" theme={"theme":{"light":"github-light","dark":"dracula"}}
const path = "/path/to/package.json";
const file = Bun.file(path);

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

***

有关在 Bun 中使用 `Buffer` 及其他二进制数据格式的更多信息，请参阅 [二进制数据 > Buffer](/runtime/binary-data#buffer)。
