skills/bun-guides-binary-arraybuffer-to-array/SKILL.md
Convert an ArrayBuffer to an array of numbers
npx skillsauth add jarle/bun-skills Bun Convert an ArrayBuffer to an array of numbersInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
To retrieve the contents of an ArrayBuffer as an array of numbers, create a Uint8Array over of the buffer. and use the Array.from() method to convert it to an array.
const buf = new ArrayBuffer(64);
const arr = new Uint8Array(buf);
arr.length; // 64
arr[0]; // 0 (instantiated with all zeros)
The Uint8Array class supports array indexing and iteration. However if you wish to convert the instance to a regular Array, use Array.from(). (This will likely be slower than using the Uint8Array directly.)
const buf = new ArrayBuffer(64);
const uintArr = new Uint8Array(buf);
const regularArr = Array.from(uintArr);
// number[]
See Docs > API > Binary Data for complete documentation on manipulating binary data with Bun.
development
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling