Why is creating a Float32Array with an offset that isn't a multiple of the element size not allowed?

后端 未结 3 1744
伪装坚强ぢ
伪装坚强ぢ 2020-12-15 22:35

I\'d like to read a binary file with a few 32 bit float values at byte offset 31.

Unfortunately, new Float32Array(buffer, 31, 6); does not work. An offs

3条回答
  •  醉酒成梦
    2020-12-15 23:15

    DataView.getFloat32() would be the best way to do this. DataView is designed for packed data and allows unaligned access to the data in an ArrayBuffer so you can pass in odd offsets like 31.

提交回复
热议问题