Skip to content

Instantly share code, notes, and snippets.

@martijnvogten
Created March 21, 2012 11:33
Show Gist options
  • Save martijnvogten/2146325 to your computer and use it in GitHub Desktop.
Save martijnvogten/2146325 to your computer and use it in GitHub Desktop.
load binary file
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