问题
The ByteArray class provides methods and properties to optimize reading, writing, and working with binary data.
How to use byte arrays tutorial.
I'm looking for a very similar API as the one linked.
I'm looking for a class the browser provides not hack or workaround. The linked question does not provide the answer. If it does please provide a link to the documentation.
Some one linked to another question but that did not answer my question.
Update: Someone off list pointed me to this class:
https://gist.github.com/sunetos/275610#file-bytearray-js
It has most or all of the read methods but none of the write methods and it's not native to the browser.
回答1:
Modern browsers support Uint8Array, one of JavaScript's TypedArray classes.
var data = new Uint8Array(8);
var data = new Uint8Array([0x10, 0x12]);
It does not have built-in methods for encoding/decoding Unicode strings. See Converting between strings and ArrayBuffers for examples of how to do that.
回答2:
The answer is yes, here are the relevant docs since you just wanted this...
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
The linked docs for each type in the above docs show the methods available on each type. IE: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array
来源:https://stackoverflow.com/questions/34521944/does-javascript-support-a-bytearray-class-in-the-browser