Node.js Buffer API 早於 ArrayBuffer 被引入 JavaScript 語言。Bun 同時實現了兩者。
使用靜態 Buffer.from() 方法從 ArrayBuffer 創建 Buffer。
ts
const arrBuffer = new ArrayBuffer(64);
const nodeBuffer = Buffer.from(arrBuffer);要創建一個只查看底層緩沖區部分的 Buffer,請將偏移量和長度傳遞給構造函數。
ts
const arrBuffer = new ArrayBuffer(64);
const nodeBuffer = Buffer.from(arrBuffer, 0, 16); // 查看前 16 字節有關使用 Bun 操作二進制數據的完整文檔,請參閱 文檔 > API > 二進制數據。