讀取檔案到 Uint8Array
Bun.file() 函式接受一個路徑並傳回一個 BunFile 例項。BunFile 擴充套件了 Blob,因此你可以以多種格式延遲讀取檔案。
要將檔案讀取到 Uint8Array 中,請使用 .bytes()。
TypeScript
const path = "/path/to/package.json";
const file = Bun.file(path);
const byteArray = await file.bytes();
byteArray[0]; // first byte
byteArray.length; // length of byteArray
有關在 Bun 中使用 Uint8Array 和其他二進位制資料格式的更多資訊,請參閱型別化陣列。