Categories
JavaScript Answers

How to convert a binary Node.js Buffer to JavaScript ArrayBuffer?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *