Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gliese1337/1037217 to your computer and use it in GitHub Desktop.
Save gliese1337/1037217 to your computer and use it in GitHub Desktop.
readAsArrayBuffer polyfill for Firefox 4 with caching
if (!FileReader.prototype.readAsArrayBuffer) {
FileReader.prototype.readAsArrayBuffer = function readAsArrayBuffer () {
this.readAsBinaryString.apply(this, arguments);
this.__defineGetter__('resultString', this.__lookupGetter__('result'));
Object.defineProperty(this, 'result', {
get : function () {
var string = this.resultString,
result = new Uint8Array(string.length);
for (var i = 0; i < string.length; i++) {
result[i] = string.charCodeAt(i);
}
//only incur the cost of copying once!
this.__defineGetter__('result', function(){
return result.buffer;
});
return result.buffer;
},configurable:true
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment