3 ms·
Magnets heh. In JavaScript you have basically two options: The legacy way is dealing with binary data as an ASCII String - effectively a string of bytes. This
by nddrylliog 15y ago
Magnets heh. In JavaScript you have basically two options:
The legacy way is dealing with binary data as an ASCII String - effectively a string of bytes. This works but it's hella slow - probably because browsers didn't think we'd be using 67MB strings :)
The new way is with Typed Arrays: using an Uint8Array is pretty awesome, see the [Mozilla Developer Docs](https://developer.mozilla.org/en/JavaScript_typed_arrays https://developer.mozilla.org/en/JavaScript_typed_arrays).
Mozilla Firefox since version 4.0 allows to do XMLHttpRequests (xhr) to be retrieved directly as an ArrayBuffer, which you can then create an Uint8Array view on. Since Gecko 6.0 (Firefox 6.0), mozResponseByteArray is deprecated and they've implemented the new standard way: see https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Receiving_binary_data_using_JavaScript_typed_arrays https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHtt... for more details.
As for reading local files, the [W3C File API Draft](http://dev.w3.org/2006/webapi/FileAPI/ http://dev.w3.org/2006/webapi/FileAPI/) is implemented in Firefox 4.0 and Chrome 11+ as far as I can tell, and it also allows us to retrieve a binary string.