Skip to content

Bun.file() 関数はパスを受け付け、BunFile インスタンスを返します。BunFile クラスは Blob を拡張し、さまざまな形式でファイルを遅延読み取りできます。.text() を使用して内容を文字列として読み取ります。

ts
const path = "/path/to/file.txt";
const file = Bun.file(path);

const text = await file.text();
// 文字列

相対パスはすべて、プロジェクトルート(package.json ファイルを含む最も近いディレクトリ)に対して解決されます。

ts
const path = "./file.txt";
const file = Bun.file(path);

Bun by www.bunjs.com.cn 編集