读取文件到 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 和其他二进制数据格式的更多信息,请参阅类型化数组。