Skip to main content
Bun.file() 函数接受一个路径并返回一个 BunFile 实例。BunFile 类继承自 Blob,允许你以多种格式懒惰地读取文件。使用 .text() 以字符串形式读取文件内容。
const path = "/path/to/file.txt";
const file = Bun.file(path);

const text = await file.text();
// string

任何相对路径都会相对于项目根目录(包含最近的 package.json 文件的目录)进行解析。
const path = "./file.txt";
const file = Bun.file(path);