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
🌐
Bun
bun.com › docs › guides › binary › typedarray-to-blob
Convert a Uint8Array to a Blob - Bun
3 weeks ago - const arr = new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]); const blob = new Blob([arr]); console.log(await blob.text()); // => "hello"
🌐
Bun
bun.com › guides › binary › typedarray-to-blob
Convert a Uint8Array to a Blob | Bun Examples
const arr = new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f]); const blob = new Blob([arr]); console.log(await blob.text()); // => "hello"
Discussions

javascript - Trouble changing a Uint8Array into a blob - Stack Overflow
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'm writing something that takes a canvas (with 1 bit pixel colour depth), converts it into a Uint8Array (with one byte representing 8 pixels) then sends it out while receiving other similarly encoded messages. I figured blobs ... More on stackoverflow.com
🌐 stackoverflow.com
March 13, 2013
javascript - How to go from Blob to ArrayBuffer - Stack Overflow
Copy// ArrayBuffer -> Blob var ... // 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 ... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to convert Uint8Array to image - Stack Overflow
i am working on a project that has multi image upload option with zip. I open the zip through JSZip and inside there is a compressed content which is contain Uint8Array, but all my attemps to conve... More on stackoverflow.com
🌐 stackoverflow.com
March 31, 2021
Javascript - Save typed array as blob and read back in as binary data - Stack Overflow
In fact, when I save the file, I can open it, and it is plainly human readable. I.E. if my Uint8Array was {"0" : "51", "1" : "52", "2" : "53" } I can open the downloaded blob in a text editor and I just see "515253" which I don't think is what should be happening. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Webdevtutor
webdevtutor.net › blog › javascript-blob-from-uint8array
How to Create a Blob from Uint8Array in JavaScript
javascript const uint8Array = new Uint8Array([72, 101, 108, 108, 111]); // Example Uint8Array const blob = new Blob([uint8Array]);
🌐
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]); PDF - Download JavaScript for free · Previous Next · SUPPORT & PARTNERS · Advertise with us · Contact us · Cookie Policy · Privacy Policy · STAY CONNECTED ...
🌐
Stack Overflow
stackoverflow.com › questions › 15383505 › trouble-changing-a-uint8array-into-a-blob
javascript - Trouble changing a Uint8Array into a blob - Stack Overflow
March 13, 2013 - Now, using the console.log after the blob is created I'm able to see the length of the blob, which should be 2035 and is in Chrome, but on other webkit browsers (Safari) the size is 19. This is because, instead of making a blob out of the Uint8Array it's making a blob out of the words "[object Uint8Array]" which is obviously useful to no one.
🌐
Webkitx
webkitx.com › doc › light › Working with Blob and Uint8Array.html
Working with Blob and Uint8Array
WebKitX supports read and write of Blob and Uint8Array byte arrays from files directly in JavaScript by exposing the following methods on the main window frame: ... The methods accept both absolute and relative paths. To use relative paths like the example below, you must handle the OnCreate ...
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 ;)

Find elsewhere
🌐
GitHub
gist.github.com › jdnichollsc › 78a6eb093731cf3e8dfd536dbe4befb3
Convert to Blob with Javascript · GitHub
Convert to Blob with Javascript. GitHub Gist: instantly share code, notes, and snippets.
🌐
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 - It is implemented using Uint8Array and is designed to handle data in a way that is compatible with a wide range of I/O operations. Buffer objects can be created from strings, arrays, or other sources of data. That’s it! In summary, ArrayBuffer, Uint8Array, Blob, and Buffer are all JavaScript objects used for handling binary data.
🌐
Stack Overflow
stackoverflow.com › questions › 66891863 › how-to-convert-uint8array-to-image
javascript - How to convert Uint8Array to image - Stack Overflow
March 31, 2021 - Compare the length of the Uint8Arrays to the file sizes of the images: you're trying to create an image from the compressed file's bytes, not the original image's bytes. ... I think you are iterating over the zip entries correctly but you need another (async?) step to uncompress the individual zip values... probably zipValues[i].async("blob", blob -> ...)
🌐
Webdevtutor
webdevtutor.net › blog › javascript-blob-uint8array
Working with JavaScript Blob and Uint8Array
Blobs are particularly useful for handling large files or binary data that needs to be sent over the network. You can create a Blob from an array of data using the Blob constructor, and then manipulate it as needed. For example, you can create a Blob from a Uint8Array and then use it to generate ...
🌐
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
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.5.1 Documentation
It is possible to create a new Buffer that shares the same allocated memory as a <TypedArray> instance by using the TypedArray object's .buffer property in the same way. Buffer.from() behaves like new Uint8Array() in this context.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Blob › arrayBuffer
Blob: arrayBuffer() method - Web APIs - MDN Web Docs
December 2, 2023 - The arrayBuffer() method of the Blob interface returns a Promise that resolves with the contents of the blob as binary data contained in an ArrayBuffer.
🌐
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
var returnedArrayBuffer = video.data;//extracting the ArrayBuffer element from BSON document console.log(returnedArrayBuffer); var newVideoBlob = new Blob([returnedArrayBuffer], { type: 'video/webm;codecs="vp8,opus"' });//have also tried with ...
🌐
Medium
medium.com › @rgndunes › playing-with-binary-data-arraybuffer-typedarray-uint8-uint16-dataview-blob-c29ff690f593
Playing with Binary data — ArrayBuffer, TypedArray (Uint8, Uint16), DataView, Blob | by Divyansh Singh | Medium
June 11, 2024 - For example, the Uint8Array [255, 128, 64, 32] is interpreted as [32895, 8256] in a Uint16Array because of how the bytes are read together. A DataView is a built-in JavaScript object that provides a low-level interface for reading and writing multiple number types in an ArrayBuffer, without ...
🌐
Stack Overflow
stackoverflow.com › questions › 41904272 › transfer-uint8array-from-browser-to-node › 41905116
javascript - Transfer Uint8Array from browser to node - Stack Overflow
the obvious first step is to not pass the blob, but to make sure to tell Node that this is in fact a uint8array by converting it with something like npmjs.com/package/to-arraybuffer