1

I'm not sure if I understand the concept of UInt8Array right, but I'm trying to convert any given data which can be image/png,jpg,gif text/html,json,js,css,less or any type of data including octet binary and then I can create data type UInt8Array

So, for any given data how can I convert them so I can make this possible?

var value = new Uint8Array([2, 4, 6, 8]);

Obviously that numbers in the array is hardcoded with random numbers, but the idea I think I want that part to be the data that I'm trying to convert to.

1 Answer 1

1

If you can get the data in a Base64 string MDN can help with this.

To sum up, use base64DecToArr

var myArray = base64DecToArr("QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw=="); // "Base 64 \u2014 Mozilla Developer Network"

var myBuffer = base64DecToArr("QmFzZSA2NCDigJQgTW96aWxsYSBEZXZlbG9wZXIgTmV0d29yaw==").buffer; // "Base 64 \u2014 Mozilla Developer Network"

alert(myBuffer.byteLength);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.