I know you can get an arraybuffer from an XMLHttpRequest in JavaScript.
var oReq = new XMLHttpRequest();
oReq.open("GET", "/myfile.png", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response; // Note: not oReq.responseText
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
for (var i = 0; i < byteArray.byteLength; i++) {
// do something with each byte in the array
}
}
};
oReq.send(null);
Is there a way to simply inline into the JavaScript source code an array buffer? Something like this:
var buffer = new ArrayBuffer([
1, 5, 32, 31, ...
])
I won't be able to assume a Uint8Array structure, the array buffer data will consist of 3-bit, 4-bit, etc., sequences, so ideally there would be some way to create an array buffer inline, maybe even:
var buffer = new ArrayBuffer('1010101011110000011001101010101011011000')...
Does anything like this exist, or is XMLHttpRequest the only way to do this in the browser?