Skip to content

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

ファイルを Uint8Array インスタンスに読み取るには、.bytes() を使用して BunFile の内容を取得します。

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

const byteArray = await file.bytes();

byteArray[0]; // 最初の byteArray
byteArray.length; // byteArray の長さ

Bun での Uint8Array やその他のバイナリデータ形式の操作の詳細については、API > バイナリデータ > 型付き配列 ドキュメントを参照してください。

Bun by www.bunjs.com.cn 編集