I don't know why the author did wrap his Uint8Array in a new one... note that I don't really know either the deprecated BlobBuilder API, but one typo I can see in your code is that you need to wrap your TypedArray in a normal Array:

new Blob([new Uint8Array(buffer, byteOffset, length)]);

The Blob() constructor takes a blobParts sequence as first parameter, and then searches for BufferSource, USVStrings and Blob elements in this sequence. So when you pass a TypedArray, it will actually iterate over all the entries of this TypedArray and treat these as USVString (and thus convert their numerical value to UTF-8 strings in the Blob). That's rarely what you want, so better always pass an Array in this constructor.

Note that if you don't need to slice the buffer, it's probably better to directly pass it instead of using an intermediary Uint8Array (but still in a normal Array):

new Blob([buffer]);
Answer from Kaiido on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Blob › arrayBuffer
Blob: arrayBuffer() method - Web APIs - MDN Web Docs
December 2, 2023 - A promise that resolves with an ArrayBuffer that contains the blob's data in binary form. While this method doesn't throw exceptions, it may reject the promise. This can happen, for example, if the reader used to fetch the blob's data throws an exception.
Discussions

How to go from Blob to ArrayBuffer
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. I was studying Blobs, and I noticed that when you have an ArrayBuffer, you can easily convert this to a Blob as follows: More on stackoverflow.com
🌐 stackoverflow.com
reactjs - How to convert ArrayBuffer to blob so it can be converted to URL for video playback - Stack Overflow
I'm trying to create a React.js app that can record short video clips, store them in MongoDB, then retrieve those clips from Mongo at another time and playback for the user. I'm able to record video More on stackoverflow.com
🌐 stackoverflow.com
node.js - What is the correct way to send ArrayBuffer or Blob across and reconstruct them? - Stack Overflow
I've read through a dozen posts on how to convert between ArrayBuffer to Blob or to Uint8Array etc. before sending the data to the client side... but I can't seem to be able to get it to work at all. More on stackoverflow.com
🌐 stackoverflow.com
[AskJS] Webworkers: passing blobs faster than passing ArrayBuffers as transferable in Chrome
what about with an "await blob.arrayBuffer" included(?) More on reddit.com
🌐 r/javascript
4
16
March 26, 2025
🌐
Bun
bun.com › docs › guides › binary › arraybuffer-to-blob
Convert an ArrayBuffer to a Blob - Bun
3 weeks ago - const buf = new ArrayBuffer(64); const blob = new Blob([buf], { type: "application/octet-stream" }); blob.type; // => "application/octet-stream" See Binary Data. Was this page helpful? YesNo · Suggest editsRaise issue · Convert an ArrayBuffer to a Buffer ·
Top answer
1 of 7
162

You can use FileReader to read the Blob as an ArrayBuffer.

Here's a short example:

var arrayBuffer;
var fileReader = new FileReader();
fileReader.onload = function(event) {
    arrayBuffer = event.target.result;
};
fileReader.readAsArrayBuffer(blob);

Here's a longer example:

// ArrayBuffer -> Blob
var uint8Array  = new Uint8Array([1, 2, 3]);
var arrayBuffer = uint8Array.buffer;
var blob        = new Blob([arrayBuffer]);

// Blob -> ArrayBuffer
var uint8ArrayNew  = null;
var arrayBufferNew = null;
var fileReader     = new FileReader();
fileReader.onload  = function(event) {
    arrayBufferNew = event.target.result;
    uint8ArrayNew  = new Uint8Array(arrayBufferNew);

    // warn if read values are not the same as the original values
    // arrayEqual from: http://stackoverflow.com/questions/3115982/how-to-check-javascript-array-equals
    function arrayEqual(a, b) { return !(a<b || b<a); };
    if (arrayBufferNew.byteLength !== arrayBuffer.byteLength) // should be 3
        console.warn("ArrayBuffer byteLength does not match");
    if (arrayEqual(uint8ArrayNew, uint8Array) !== true) // should be [1,2,3]
        console.warn("Uint8Array does not match");
};
fileReader.readAsArrayBuffer(blob);
fileReader.result; // also accessible this way once the blob has been read

This was tested out in the console of Chrome 27—69, Firefox 20—60, and Safari 6—11.

Here's also a live demonstration which you can play with: https://jsfiddle.net/potatosalad/FbaM6/

Update 2018-06-23: Thanks to Klaus Klein for the tip about event.target.result versus this.result

Reference:

  • https://developer.mozilla.org/en-US/docs/Web/API/FileReader#readAsArrayBuffer()
  • https://www.w3.org/TR/FileAPI/#dfn-readAsArrayBuffer
2 of 7
77

The Response API consumes a (immutable) Blob from which the data can be retrieved in several ways. The OP only asked for ArrayBuffer, and here's a demonstration of it.

var blob = GetABlobSomehow();

// NOTE: you will need to wrap this up in a async block first.
/* Use the await keyword to wait for the Promise to resolve */
const arrayBuffer = await new Response(blob).arrayBuffer();

Alternatively you could use this:

new Response(blob).arrayBuffer().then((arrayBuffer) => {
 // do something with the arrayBuffer
});

Note: This API isn't compatible with older (ancient) browsers so take a look to the Browser Compatibility Table to be on the safe side ;)

🌐
Stack Overflow
stackoverflow.com › questions › 63541909 › how-to-convert-arraybuffer-to-blob-so-it-can-be-converted-to-url-for-video-playb
reactjs - How to convert ArrayBuffer to blob so it can be converted to URL for video playback - Stack Overflow
This videoBlob can be converted via URL.createObjectUrl and set to the src attribute in the HTML video tag. In this case, the video plays back just fine. ... If I store this videoBlob in MongoDB, it's converted into a BSON document which contains an ArrayBuffer element in the following format.
🌐
Rip Tutorial
riptutorial.com › converting between blobs and arraybuffers
JavaScript Tutorial => Converting between Blobs and ArrayBuffers
var array = new Uint8Array([0x04, 0x06, 0x07, 0x08]); var blob = new Blob([array]); ... Get monthly updates about new articles, cheatsheets, and tricks. ... This website stores cookies on your computer.
Find elsewhere
🌐
Medium
lucas-chow.medium.com › file-blob-arraybuffer-576a8e99de0d
File, Blob, ArrayBuffer. To start All of this, you need get a… | by Lucas Chow | Medium
May 26, 2020 - Since a Blob consists of ArrayBuffer and something else, you can create a Blob from TypedArray raw data.
🌐
Reddit
reddit.com › r/javascript › [askjs] webworkers: passing blobs faster than passing arraybuffers as transferable in chrome
r/javascript on Reddit: [AskJS] Webworkers: passing blobs faster than passing ArrayBuffers as transferable in Chrome
March 26, 2025 -

I'm running some tests in Chrome with webworker and I'm finding quite odd that passing blobs back and forth is way, way faster than ArrayBuffers.

This is the testing code I'm using with a 1Gb file:

ArrayBuffer:

const buffer = await fetch('./1GbFile.bin').then(data => data.arrayBuffer());

console.time("Buffer")
worker.onmessage = function(e) {
  console.timeEnd("Buffer");
};

worker.onerror = function(e) {
  reject(e.message);
};

worker.postMessage(buffer, [buffer]);

Blob:

const blob = await fetch('./1GbFile.bin').then(data => data.blob());

console.time("Blob")
worker.onmessage = function(e) {
  console.timeEnd("Blob");
};

worker.onerror = function(e) {
  reject(e.message);
};

worker.postMessage(blob);

And this is the webworker, it just returns the same data it receives:

self.onmessage = function(e) {
    const data = e.data;
    if (data instanceof ArrayBuffer)
        self.postMessage(data, [data]);
    else
        self.postMessage(data);
}

And the staggering results:

Buffer: 34.46484375 ms
Blob: 0.208984375 ms

I knew blob was very optimized in this scenario, but I thought using the transferable option would make it work somehow similar, but it's more than 100 times slower.

And the transferable option is definitely doing its thing, removing the option makes it like 10 times slower.

Edit: The same code is way faster in Firefox:

Buffer: 2ms
Blob: 0ms

🌐
GitHub
gist.github.com › robnyman › 1875241
Get file as an arraybuffer, create blob, read through FileReader and save in localStorage · GitHub
Get file as an arraybuffer, create blob, read through FileReader and save in localStorage - arraybuffer-blob-filereader-localStorage.js
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
Blob
May 16, 2022 - The Blob constructor allows to create a blob from almost anything, including any BufferSource. But if we need to perform low-level processing, we can get the lowest-level ArrayBuffer from blob.arrayBuffer():
🌐
Reality Ripple
udn.realityripple.com › docs › Web › API › Blob › arrayBuffer
Blob.arrayBuffer() - Web APIs
A promise that resolves with an ArrayBuffer that contains the blob's data in binary form. While this method doesn't throw exceptions, it may reject the promise. This can happen, for example, if the reader used to fetch the blob's data throws an exception.
🌐
YouTube
youtube.com › watch
Deep Dive into Blobs, Files, and ArrayBuffers
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Top answer
1 of 3
149

Summary

Unless you need the ability to write/edit (using an ArrayBuffer), then Blob format is probably best.

Detail

I came to this question from a different html5rocks page., and I found @Bart van Heukelom's comments to be helpful, so I wanted to elevate them to an answer here.

I also found helpful resources specific to ArrayBuffer and Blob objects. In summary: despite the emphasis on Blob being immutable/"raw data" Blob objects are easy to work with.

Resources that compare / contrast ArrayBuffer vs Blob:

  • Mutability
    • an ArrayBuffer can be changed (e.g. with a DataView)
    • a Blob is immutable
  • Source / Availability in Memory
    • Quoting Bart van Heukelom:
    • An ArrayBuffer is in the memory, available for manipulation.
    • A Blob can be on disk, in cache memory, and other places not readily available
  • Access Layer
    • ArrayBuffer will require some access layer like typed arrays
    • Blob can be passed directly into other functions like window.URL.createObjectURL, as seen in the example from OP's URL.
      • However, as Mörre points out you may still need File-related interfaces and API's like FileReader to work with a Blob.
  • Convert / Generate
    • You can generate Blob from ArrayBuffer and vice versa, which addresses the OP's "Aren't both containers comprised of bits?"
    • ArrayBuffer can be generated from a Blob using the FileReader's readAsArrayBuffer method , or the async method const arrayBuffer = await blob.arrayBuffer() (thanks to @Darren G)
    • Blob can be generated from an ArrayBuffer as @user3405291 points out new Blob([new Uint8Array(data)]);, shown in this answer
  • Use in Other Libraries
    • jsZip; (new JSZip()).loadAsync(...) accepts both ArrayBuffer and Blob: String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob/Promise
  • How does protocol handle ArrayBuffer vs Blob
    • Websocket (aka WS / WSS)
      • Use the webSocket's binaryType property (could have values "arraybuffer" or "blob") to "control the type of binary data being received over the WebSocket connection."
    • XmlHttpRequest (aka XHR)
      • Use the xhr's responseType property to "to change the expected response type from the server" (valid values include "arraybuffer", "blob", and others like "document", "json", and "text")
      • the response property will contain the entity body according to responseType, as an ArrayBuffer, Blob, Document, JSON, or string.

Other helpful documentation:

  • ArrayBuffer

The ArrayBuffer object is used to represent a generic, fixed-length raw binary data buffer. You cannot directly manipulate the contents of an ArrayBuffer; instead, you create one of the typed array objects or a DataView object which represents the buffer in a specific format, and use that to read and write the contents of the buffer.

  • Blob

A Blob object represents a file-like object of immutable, raw data. Blob represent data that isn't necessarily in a JavaScript-native format. The File interface is based on Blob, inheriting blob functionality and expanding it to support files on the user's system.

2 of 3
27

It's explained on the page.

ArrayBuffer

An ArrayBuffer is a generic fixed-length container for binary data. They are super handy if you need a generalized buffer of raw data, but the real power behind these guys is that you can create "views" of the underlying data using JavaScript typed arrays. In fact, multiple views can be created from a single ArrayBuffer source. For example, you could create an 8-bit integer array that shares the same ArrayBuffer as an existing 32-bit integer array from the same data. The underlying data remains the same, we just create different representations of it.

BLOB

If you want to work directly with a Blob and/or don't need to manipulate any of the file's bytes, use xhr.responseType='blob':

🌐
SitePoint
sitepoint.com › javascript
Blobs and arrayBuffers - JavaScript
August 13, 2017 - I’ve been using the fetch API. Most examples use .json() to resolve the response body as JSON. Alternatively, fetch offers the methods arrayBuffer() and blob() to take the response stream and return a arrayBuffer or blo…
🌐
Medium
medium.com › @naveenkumarasinghe › javascript-lost-in-binaries-buffer-blob-uint8array-arraybuffer-ed8d2b4de44a
JavaScript: Lost in binaries — Buffer/Blob/UInt8Array/ArrayBuffer | by Naveen Kumarasinghe | Medium
April 2, 2023 - Blobs have additional encoding and metadata on top of binary data. These can also be created from strings, arrays, or other sources of data. Due to encoding blobs are usually less space efficient than ArrayBuffer and Uint8Array.
🌐
Reddit
reddit.com › r/javascript › [askjs] suddenly blob creation from large typed array is no longer allowed?
r/javascript on Reddit: [AskJS] Suddenly blob creation from large typed array is no longer allowed?
July 4, 2024 -

This is just a demo code snippet and its variations are working perfectly for more than a year until now.

I suspect the recent browser updates for Edge 126.0.2592.87 (Official build) (64-bit) and Chrome 126.0.6478.127 (Official Build) (64-bit) breaks it, because they used the same underlying engine. Firefox seems to be still okay.

var myArray = new Uint8Array(1024 * 1024 * 1024 * 1.8);
var myBlob = new Blob([myArray], {type: "*.*"});
myBlob.slice(0, 10).arrayBuffer();

If the code snippet works in the first run then rerun it twice without refreshing browser. You will be greeted with the message "Uncaught DOMException: The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired."

Any thoughts or insights? Appreciated.

Top answer
1 of 2
11
You are trying to create a ~2 GB TypedArray, then create a ~2 GB Blob. Then create a 10 byte Blob, then a 10 byte ArrayBuffer. That's ~4 GB of RAM. In 3 lines of code. You are probably running out of RAM. Blob storage is not contigous in Chrome. See Where is Blob binary data stored? . You really don't need to create the Blob at all, unless you are using stream() method or creating an Blob URL for some programming reasons. Just use subarray() method of TypedArray to get 10 bytes from the ~2 GB underlying ArrayBuffer source of the initial Uint8Array you create. The type "*.*" is not a valid MIME type. You should probably use "application/octet-stream" or just "text/plain" for binary data. 1024 * 1024 * 1024 * 1.8 outputs a float, 1932735283.2. You probably want to use Math.ceil(1024 * 1024 * 1024 * 1.8) to round up.
2 of 2
2
I'm pretty sure this doesn't have anything to do with Chrome versions but with your free space (RAM and Disk). // CrOS: // * Ram - 20% // * Disk - 50% // Note: The disk is the user partition, so the operating system can still // function if this is full. // Android: // * RAM - 1% // * Disk - 6% // Desktop: // * Ram - 20%, or 2 GB if x64. // * Disk - 10% This is a comment on the function used by Chrome to estimate the amount of Blob storage limits. Usually a Blob is read/write from disk when the memory (RAM) pressure is high so Chrome tries to write the blob to disk, but only if there's enough free space in the disk (otherwise this could lead to potential securiity issues). As you can see there's a max limit for Blobs of 2GB (on x64) but this should not be the problem because you're allocating 1.8GB. If you want to take a look at the source code: https://source.chromium.org/chromium/chromium/src/+/main:storage/browser/blob/blob_memory_controller.cc;l=75;drc=d311b843fa6d3cfd69f650d05cd44ace6aaa968d;bpv=1;bpt=1
🌐
GitHub
gist.github.com › jens1101 › 05049038f545f3c7e0bfba09bece83e6
Convert an ArrayBuffer to a Blob · GitHub
Convert an ArrayBuffer to a Blob. GitHub Gist: instantly share code, notes, and snippets.
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.5.1 Documentation
The intent is for type to convey the MIME media type of the data, however no validation of the type format is performed. Creates a new Blob object containing a concatenation of the given sources. <ArrayBuffer>, <TypedArray>, <DataView>, and <Buffer> sources are copied into the 'Blob' and can ...