Instances of Buffer are also instances of Uint8Array in node.js 4.x and higher. Thus, the most efficient solution is to access the buffer's own .buffer property directly, as per https://stackoverflow.com/a/31394257/1375574. The Buffer constructor also takes an ArrayBufferView argument if you need to go the other direction.

Note that this will not create a copy, which means that writes to any ArrayBufferView will write through to the original Buffer instance.


In older versions, node.js has both ArrayBuffer as part of v8, but the Buffer class provides a more flexible API. In order to read or write to an ArrayBuffer, you only need to create a view and copy across.

From Buffer to ArrayBuffer:

function toArrayBuffer(buffer) {
  const arrayBuffer = new ArrayBuffer(buffer.length);
  const view = new Uint8Array(arrayBuffer);
  for (let i = 0; i < buffer.length; ++i) {
    view[i] = buffer[i];
  }
  return arrayBuffer;
}

From ArrayBuffer to Buffer:

function toBuffer(arrayBuffer) {
  const buffer = Buffer.alloc(arrayBuffer.byteLength);
  const view = new Uint8Array(arrayBuffer);
  for (let i = 0; i < buffer.length; ++i) {
    buffer[i] = view[i];
  }
  return buffer;
}
Answer from Martin Thomson on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › ArrayBuffer
ArrayBuffer - JavaScript - MDN Web Docs
It is an array of bytes, often referred to in other languages as a "byte array". 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.
🌐
JavaScript.info
javascript.info › tutorial › binary data, files
ArrayBuffer, binary arrays
July 11, 2022 - Let’s eliminate a possible source of confusion. ArrayBuffer has nothing in common with Array: It has a fixed length, we can’t increase or decrease it. It takes exactly that much space in the memory. To access individual bytes, another “view” object is needed, not buffer[index].
Discussions

node.js - Convert a binary NodeJS Buffer to JavaScript ArrayBuffer - Stack Overflow
How can I convert a NodeJS binary buffer into a JavaScript ArrayBuffer? More on stackoverflow.com
🌐 stackoverflow.com
javascript - What is the difference between an array and an ArrayBuffer? - Stack Overflow
I'm just wondering why everyone uses ArrayBuffer instead of just a normal array, string or stringified JSON for sending messages from the server to the client. Is it more efficient? Also, just won... More on stackoverflow.com
🌐 stackoverflow.com
typed arrays: make Buffers and ArrayBuffers interchangeable?
I've updated our typed arrays implementation to be more in line with the Khronos spec and the browser but it's not a change that's unequivocally for the better: Buffers are now cloned i... More on github.com
🌐 github.com
8
February 10, 2013
javascript - What is the difference between an ArrayBuffer and a Blob? - Stack Overflow
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. ... A Blob object represents a file-like object of immutable, raw data. Blob represent data that isn't necessarily in a JavaScript... More on stackoverflow.com
🌐 stackoverflow.com
February 23, 2017
🌐
Webdevtutor
webdevtutor.net › blog › javascript-buffer-vs-arraybuffer
JavaScript Buffer vs ArrayBuffer: Understanding the Differences
This can be both advantageous and risky, as it allows for efficient data manipulation but also requires careful handling to avoid unexpected changes. On the other hand, ArrayBuffer is a built-in object in JavaScript that represents a fixed-length raw binary data buffer.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-the-difference-between-an-array-and-an-arraybuffer
What is the Difference Between an Array and an ArrayBuffer? - GeeksforGeeks
July 23, 2025 - An ArrayBuffer is a low-level binary data buffer. It is used to handle raw binary data and is primarily used in the scenarios where you need to work with the streams of binary data such as in WebSockets or when manipulating data from the files.
🌐
CodeForGeek
codeforgeek.com › home › node.js buffer vs arraybuffer: the senior engineer’s guide to binary data in 2026
Node.js Buffer vs ArrayBuffer: The Senior Engineer's Guide to Binary Data in 2026 | CodeForGeek
April 15, 2026 - The short answer is this: ArrayBuffer is the web standard for binary data that works in browsers and Node.js, but Buffer is Node.js-specific and gives you performance advantages for I/O-heavy operations.
🌐
Restack
restack.io › p › javascript-ai-search-optimization-techniques-answer-buffer-vs-arraybuffer-cat-ai
Where teams design, test and optimize agents at Enterprise Scale — Restack
April 26, 2025 - The open-source stack enabling teams to improve their agent experience while engineers make them reliable at scale on Kubernetes.
Top answer
1 of 1
41

An ArrayBuffer is more than just a simple array. It contains raw binary data. This is very useful for direct memory manipulation and conserving space.

When you create a normal array, you won't get a proper set of contiguous memory in many cases since arrays can contain any combination of different kinds of objects. This is useful when you have dynamic data and multiple types together (frequently happens in JS) but is not so useful when you know the exact layout of memory that you need.

This also allows you to view the data at the byte level. For example, it's pretty common in binary data formats to have a n byte long identifier number, an m byte long field telling you how many bytes are used for this field, and m' bytes of data that actually makes up the data field.

[ identifier ][ bytes of data ][ data ]

With an ArrayBuffer, you have the option of moving through that data on the byte level by using various Views. A regular array doesn't allow you to move through the data with that level of granularity because no guarantees are made about the memory layout.

Finally, because you are telling the compiler/interpreter exactly how much space you're going to use and exactly how you're going to view it, it can do much more advanced optimizations when working with that data. When iterating through that data, it doesn't have to make calculated leaps through memory. Instead, it knows exactly how far to move ahead in memory to find the next data point.

As for what Uint8Array is, it's a typed array. Essentially, it tells the compiler/interpreter that you will be accessing this data exclusively as 8-bit uints which, again, allows it to make better optimizations. Then you can use standard array indexing on it (arr[0], arr[1], etc.) and you'll be getting back the equivalent uint values out of the array.

TL;DR They take less space when the exact data format is known, allows you to move more exactly through your data and gives the compiler/interpreter greater options for optimization.

Find elsewhere
🌐
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 - In summary, ArrayBuffer, Uint8Array, ... data. ArrayBuffer provides a fixed-size block of memory that can be manipulated with binary data, while Uint8Array provides a view into that memory for more efficient manipulation...
🌐
Medium
dev-aditya.medium.com › buffer-arraybuffer-float64array-in-node-js-ef68c112d905
Buffer, ArrayBuffer, Float64Array in Node.js | by Aditya Yadav | Medium
September 29, 2024 - Buffer: Specialized for handling binary data in Node.js applications. ArrayBuffer: A low-level binary data buffer used across different environments.
🌐
Node.js
nodejs.org › api › buffer.html
Buffer | Node.js v26.10.0 Documentation
This creates a view of the <ArrayBuffer> without copying the underlying memory. For example, when passed a reference to the .buffer property of a <TypedArray> instance, the newly created Buffer will share the same allocated memory as the <TypedArray>'s underlying ArrayBuffer.
Author: nodejs
🌐
Medium
medium.com › @conboys111 › arraybuffer-vs-standard-arrays-when-and-why-should-you-use-it-cd2891394fab
ArrayBuffer vs Standard Arrays: When and Why Should You Use It? | by myHotTake | Medium
January 18, 2025 - Efficiency: Instead of creating multiple small bowls (arrays), I use one large tray (buffer), reducing memory overhead. Interoperability: This is especially useful for working with binary data (e.g., from files or network streams). Control: I can manage how memory is used and precisely interpret it. For example, ArrayBuffer is often used when working with Web APIs like fetch for handling binary files or WebSockets for sending/receiving data.
🌐
GitHub
gist.github.com › miguelmota › 5b06ae5698877322d0ca
Node.js Buffer to ArrayBuffer · GitHub
function toArrayBuffer(buffer) { return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength); } function toBuffer(byteArray) { return Buffer.from(byteArray); }
🌐
W3Schools
w3schools.com › js › js_arraybuffers.asp
JavaScript Array Buffer
An ArrayBuffer is fixed a block of memory, often used to store typed arrays.
🌐
Medium
medium.com › @julienetienne › different-types-of-arrays-in-javascript-and-when-to-use-them-77f7843b71de
Different Types of Arrays in JavaScript + When to Use Them | by Julien Etienne | Medium
February 8, 2024 - An array-buffer is a Generic Raw Binary Data Buffer. Generic: It’s not tied down to a particular data type. It can be used to store any binary data, whether it represents integers, unsigned integers, floats, unsigned floats and strings.
🌐
Telerik
telerik.com › blogs › array-buffers-javascript
Array Buffers in JavaScript
October 22, 2025 - In JavaScript, an ArrayBuffer is defined as an object that represents a generic, fixed-length raw binary data buffer. It allows you to work with binary data directly without worrying about character encoding.
Top answer
1 of 3
151

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
28

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':