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);