Alternative to readAsBinaryString for IE10

David Jones picture David Jones · Sep 3, 2013 · Viewed 16.6k times · Source

It seems that readAsBinaryString, a method of the JavaScript FileReader object, is not supported in IE10. I've tried the following, as suggested in this HTML5 Rocks article:

String.fromCharCode.apply(null, new Uint16Array(buffer));

However, this results in an Out of stack space error.

Answer

David Jones picture David Jones · Sep 3, 2013

I found the answer here:

var binary = "";
var bytes = new Uint8Array(buffer);
var length = bytes.byteLength;
for (var i = 0; i < length; i++) {
  binary += String.fromCharCode(bytes[i]);
}