Bun Convert a Blob to a Uint8Array

Convert a Blob to a Uint8Array

jarle Updated

File contents

Convert a Blob to a Uint8Array

The Blob class provides a number of methods for consuming its contents in different formats. This snippets reads the contents to an ArrayBuffer, then creates a Uint8Array from the buffer.

const blob = new Blob(["hello world"]);
const arr = new Uint8Array(await blob.arrayBuffer());

See Docs > API > Binary Data for complete documentation on manipulating binary data with Bun.

jarle/bun-skills/tree/main/skills/bun-guides-binary-blob-to-typedarray commit 7080c7b045

Frequently asked questions

npx skillmds@latest add jarle/bun-convert-a-blob-to-a-uint8array