このコードスニペットは、特定の_絶対パス_でディスクに文字列を書き込みます。
これは、データをディスクに効率的に書き込む高速な Bun.write() API を使用します。第 1 引数は_宛先_、第 2 引数は書き込む_データ_です。
ts
const path = "/path/to/file.txt";
await Bun.write(path, "Lorem ipsum");相対パスは、プロジェクトルート(package.json ファイルを含む最も近いディレクトリ)を基準に解決されます。
ts
const path = "./file.txt";
await Bun.write(path, "Lorem ipsum");BunFile を宛先として渡すことができます。Bun.write() は、その関連するパスにデータを書き込みます。
ts
const path = Bun.file("./file.txt");
await Bun.write(path, "Lorem ipsum");Bun.write() は、ディスクに書き込まれたバイト数を返します。
ts
const path = "./file.txt";
const bytes = await Bun.write(path, "Lorem ipsum");
// => 11Bun.write() の完全なドキュメントについては、ドキュメント > API > ファイル I/O を参照してください。