views:

74

answers:

2

The generally accepted answer is that you can't. However there is mounting evidence that this is not true based on the existence of projects that read in types of data that are not basic HTML types. Some projects that do this are the JavaScript version of ProtoBuf and Smokescreen.

Smokescreen is a flash interpreter written in JS so if it is not possible to get at the bytes directly how are these projects working around this? The source to Smokescreen can be found here. I have looked it over but with JS not being my primary language right now the solution eludes me.

A: 

Protobuf does all its magic on an XMLHttpRequest.requestText field, which is just a DOMString.

regularfry
+1  A: 

They both look to be using a String (in this case the responseText of an XMLHttpRequest) directly as a collection 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;
}
jimr