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 的長度

請參閱 API > 二進制數據 > 類型化數組,了解在 Bun 中使用 Uint8Array 和其他二進制數據格式的更多信息。

Bun學習網由www.bunjs.com.cn整理維護