Created
March 21, 2012 11:33
-
-
Save martijnvogten/2146325 to your computer and use it in GitHub Desktop.
load binary file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jvm.fetchBytes = function(url) { | |
var req = new XMLHttpRequest(); | |
req.open('GET', url, false); | |
// XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com] | |
req.overrideMimeType('text/plain; charset=x-user-defined'); | |
req.send(null); | |
if (req.status != 200) { | |
throw "Could not load file"; | |
} | |
var fileContents = req.responseText; | |
var bytes = []; | |
var len = fileContents.length; | |
for ( var i = 0; i < len; i++) { | |
bytes.push(fileContents.charCodeAt(i) & 0xff); | |
} | |
return bytes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment