Typed Arrays: Y U No offset at values other than multiples of element size?

http://www.khronos.org/registry/typedarray/specs/latest/#TYPEDARRAYS


TypedArray(ArrayBuffer buffer, optional unsigned long byteOffset, optional unsigned long length)

The given byteOffset must be a multiple of the element size of the specific type, otherwise an exception is raised.

But Why?

Like, I have this color, right? And it’s prefixed with, let’s say, a 1-byte “header” value. And I want a 32 bit uint view into the color, but I can’t get it :fight:


var data = new Uint8Array([8, 255,255,255,255]);
var buffer = data.buffer;

// gimme mah colah!
var color = new Uint32Array(buffer, 1,1); // first 1 to offset into buffer 1 byte skipping `8`

“Size is too large (or is negative).” (gc)
or
“Invalid offset/length when creating typed array” (ie)
or
“Error: invalid arguments” (ff)

So I’m just expected to have to go in and piece my color (or possible collection of many consecutive 32 bit colors) through the individual bytes? (And IE don’t do no slice, so don’t even try…)

Bah! Web technologies … (holds back) … are difficult.