Sometimes, we want to convert a binary Node.js Buffer to JavaScript ArrayBuffer.
In this article, we’ll look at how to convert a binary Node.js Buffer to JavaScript ArrayBuffer.
How to convert a binary Node.js Buffer to JavaScript ArrayBuffer?
To convert a binary Node.js Buffer to JavaScript ArrayBuffer, we can use the Uint8Array
constructor.
For instance, we write
const arrayBuffer = new Uint8Array(nodeBuffer).buffer;
to create the Uint8Array
from the nodeBuffer
Node.js buffer object.
Then we get the array buffer from the buffer
property.
Conclusion
To convert a binary Node.js Buffer to JavaScript ArrayBuffer, we can use the Uint8Array
constructor.