Real user-level IO reads bytes you tell it to read and manages it's own pointer. I see a lot of this going on:
array[at++];
Which is kind of tedious and adds a layer of hard work. What if you forget an at++? Or you didn't concat the two correct bytes? Take this area of code for example,
this.animated_next = Turbo.dByteCat(array[at++], array[at++]);
this.delay = Turbo.dByteCat(array[at++], array[at++]);
It should totally become:
this.animated_next = ByteBuffer.read16();
this.delay = ByteBuffer.read16();
// ByteBuffer.js:
ByteBuffer.prototype.readInt = function() {
return Turbo.dByteCat(this.array[this.at++], this.array[this.at++])
}
No need to hand-increment raw binary pointers, and no need to manually concatenate bytes each time an int or higher is observed. It cuts down in complexity, and increases readability, and provides less areas where there are issues. I use this API to read the files in C#, for example: C# binary reader.
edit:
renamed readInt to read16, for clearer picture these are 2-byte 'short' values being read and not 4 byte integers.