skills/bun-guides-binary-arraybuffer-to-typedarray/SKILL.md
Convert an ArrayBuffer to a Uint8Array
npx skillsauth add jarle/bun-skills Bun Convert an ArrayBuffer to a Uint8ArrayInstall 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.
A Uint8Array is a typed array, meaning it is a mechanism for viewing the data in an underlying ArrayBuffer.
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer);
Instances of other typed arrays can be created similarly.
const buffer = new ArrayBuffer(64);
const arr1 = new Uint8Array(buffer);
const arr2 = new Uint16Array(buffer);
const arr3 = new Uint32Array(buffer);
const arr4 = new Float32Array(buffer);
const arr5 = new Float64Array(buffer);
const arr6 = new BigInt64Array(buffer);
const arr7 = new BigUint64Array(buffer);
To create a typed array that only views a portion of the underlying buffer, pass the offset and length to the constructor.
const buffer = new ArrayBuffer(64);
const arr = new Uint8Array(buffer, 0, 16); // view first 16 bytes
See Docs > API > Utils for more useful utilities.
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