JavaScript readAsBinaryString Function on E11

后端 未结 6 1872
攒了一身酷
攒了一身酷 2020-12-23 18:35

In this page http://www.html5rocks.com/en/tutorials/file/dndfiles/ if you scroll down to example \"Example: Slicing a file. Try it!\" you will see uses of readAsBin

6条回答
  •  無奈伤痛
    2020-12-23 19:14

    For IE 11 you can use this XHR trick:

    function blobToBinaryStringIE11(blob) {
        var blobURL = URL.createObjectURL(blob);
        var xhr = new XMLHttpRequest;
        xhr.open("get", blobURL);
        xhr.overrideMimeType("text/plain; charset=x-user-defined");
        xhr.onload = function () {
            var binary = xhr.response;
            // do stuff
        };
        xhr.send();
    }
    

    It's 20x faster than the Uint8Array + fromCharCode route and as fast as readAsBinaryString.

提交回复
热议问题