-1

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.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • Please read the question – 1.21 gigawatts Dec 30 '15 at 02:07
  • That question asked How to store a byte array. This is is there a byte array class. COMPLETELY DIFFERENT – 1.21 gigawatts Dec 30 '15 at 02:07
  • The only question was if JS supports a ByteArray Class... everything else you stated didn't change your question... – Jacques ジャック Dec 30 '15 at 02:07
  • Did you read the details? I asked for a link to documentation and a similar API. NOT the same. – 1.21 gigawatts Dec 30 '15 at 02:08
  • If there is a question that tells you how to use one, how does that not already tell you there is one? – Jacques ジャック Dec 30 '15 at 02:08
  • 3
    asking for recommendations for off-site resources is just as **off-topic** as duplicates are. –  Dec 30 '15 at 02:09
  • That is how to store byte array data. Having ByteArray class with methods that is different. – 1.21 gigawatts Dec 30 '15 at 02:09
  • There are plenty of docs linked in the answers now. – Jacques ジャック Dec 30 '15 at 02:13
  • If you want something with unicode encoding methods (like the linked example), please include that key information directly in the question. Stack Overflow posts must be able to stand alone to some extent even if their links break. – Jeremy Dec 30 '15 at 02:16
  • yay for all the downvotes! i love stack overflow! – 1.21 gigawatts Dec 30 '15 at 02:28
  • OK thanks everyone for the answers and links. After comparing Uint8Array, and so on I don't think they're the same as what I'm looking for. DataView and TypedArray looks close, http://www.html5rocks.com/en/tutorials/webgl/typed_arrays/ but lacks compress, uncompress, and a few other methods. You can see the difference in API in the tutorial linked in the question details. – 1.21 gigawatts Dec 30 '15 at 03:12
  • If you want to know how to compress, decompress, and perform other operations on byte arrays in JavaScript, ask those questions separately. I'll concede that you didn't realize that unsigned 8 bit integers are the same as bytes so I can see why you didn't think this question was a duplicate; I'm inclined to say it's not a duplicate but rather unclear/too broad. – 2rs2ts Dec 31 '15 at 23:31
  • In the ActionScript ByteArray class there isn't multiple array types. Instead there are methods to readUnsignedInt(), readInt(), readDouble(), readFloat(), readBoolean(), etc. I can go on. It is one class, not multiple. That same ByteArray class has compress() and uncompress() methods. Here is how to use it, http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7d54.html. If it seems like it is too broad a question then it means JavaScript doesn't have an equivalent. – 1.21 gigawatts Dec 31 '15 at 23:38

2 Answers2

5

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.

Community
  • 1
  • 1
Jeremy
  • 1
  • 85
  • 340
  • 366
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

Jacques ジャック
  • 3,682
  • 2
  • 20
  • 43