Skip to main content
Bun.file() 函数接受一个路径并返回一个 [BunFile] 实例。[BunFile] 类扩展了 Blob 并允许您以多种格式延迟读取文件。使用 .json() 读取并解析 .json 文件的内容为普通对象。 [BunFile] 的 MIME 类型将相应设置。
https://mintcdn.com/teemo/2s-4Z6VdGqiCeBNX/icons/typescript.svg?fit=max&auto=format&n=2s-4Z6VdGqiCeBNX&q=85&s=087b260066909db1cd3e9c7292bc34b2index.ts
const path = "/path/to/package.json";
const file = Bun.file(path);

const contents = await file.json();
// { name: "my-package" }

file.type; // => "application/json;charset=utf-8";