Skip to content

Bun.file() 関数はパスを受け付け、BunFile インスタンスを返します。BunFile クラスは Blob を拡張し、さまざまな形式でファイルを遅延読み取りできます。.json() を使用して .json ファイルの内容をプレーンオブジェクトとして読み取り解析します。

BunFile の MIME 型がそれに応じて設定されます。

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

Bun by www.bunjs.com.cn 編集