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

# 读取文件为 ArrayBuffer

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

```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 buffer = await file.arrayBuffer();
```

***

使用类型数组（如 `Int8Array`）读取 `ArrayBuffer` 的二进制内容。若要使用 `Uint8Array`，请参见 [`.bytes()`](/guides/read-file/uint8array)。

```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 buffer = await file.arrayBuffer();
const bytes = new Int8Array(buffer);

bytes[0];
bytes.length;
```

***

参见 [类型数组](/runtime/binary-data#typedarray) 了解如何在 Bun 中使用类型数组。
