How to access byte level information in JavaScript?

The generally accepted answer is that you cannot. However, there is every reason to prove that this is not true, given the existence of projects that are read in data types that are not basic HTML types. Some projects that do this are JavaScript versions of ProtoBuf and Smokescreen .

Smokescreen is a flash interpreter written in JS, so if it is not possible to directly obtain in bytes, how do these projects work around this? The source for Smokescreen can be found here . I looked through it, but with JS, which is not my main language, now the solution is eluding me.

+6
javascript bytecode byte
source share
2 answers

They both use String (in this case responseText for XMLHttpRequest ) directly as a set of bytes.

 data = ... // a binary string bytes = []; for ( i = 0; i < data.length; i++ ) { // This coverts the unicode character to a byte stripping // off anything past the first 8 bits bytes[i] = data.charCodeAt( i ) & 0xFF; } 
+1
source share

Protobuf does all its magic in the XMLHttpRequest.requestText field, which is just a DOMString.

0
source share

All Articles