We wish to use javascript to manipulate binary data. While this can be done with ArrayBuffer, ArrayBuffer is not supported in older browsers, how would you recommend doing this?
1 Answer
One option you have is to store binary data in an Array and write functions to access in the same way as ArrayBuffers and UintXArrays. This might also be a shim to DataView.
This should not be a too hard task and still performs reasonably.
An example:
function getInt8(byteOffset)
{
return (byteArray[byteOffset] << 24) >> 24; // moves sign bit to bit 32
}
function getUint8(byteOffset)
{
return byteArray[byteOffset];
}
function getUint16(byteOffset)
{
return byteArray[byteOffset] | byteArray[byteOffset + 1] << 8;
}
function setUint8(byteOffset, value)
{
byteArray[byteOffset] = value & 0xff; // make sure to mask values
}
// etc...
This requires some bitwise magic, but you should be able to figure it out with some google.
There is also a lot of content on how IE handles binary data (for instance this extensive thread about XMLHttpRequests).