6

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.

1
  • I don't know what their source looks like, but you can easily talk to flash with Javascript and let it do what JS can't Commented Jun 3, 2010 at 13:12

2 Answers 2

1

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This unfortunately does not work reliably across browsers and encodings... mostly because even using seemingly simple encoding (ISO-8859-1, aka Latin-1, which should be proper 8-bit subset of Unicode) does not actually provide you with expected direct mapping.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.