I have an application that loads user text through a XMLHttpRequest and returns it in a binary format. I understand that the main difference between 8, 16, and 32 is the amount of bytes per element but I don't know when to use each.
For example, for my application, since the text file could contain any possible characters really, which one would be best?
I have tried different files including one that that had emojis and it seemed that in the Uint8Array the emoji took up 4 indices.
Is there any reason that for my use I shouldn't just use the Uint8Array or is there a reason I should dynamically choose when the file is read? I have read the MDN docs on each but it doesn't seem to offer much insight other than byte size.
Here is the code I currently use to load the file:
asset= new XMLHttpRequest();
asset.addEventListener('readystatechange', function load() {
if (asset.readyState == 4 && asset.data.status == 200) {
const arrayBuffer = asset.data.response;
if (arrayBuffer) asset.data = new Uint8Array(arrayBuffer);
}
}.bind(this), false);
// Error handling.
asset.responseType = 'arraybuffer';
asset.open('GET', asset.src);
asset.send();