How to read binary data in IE9?

后端 未结 2 1638
梦谈多话
梦谈多话 2021-01-31 19:15

I\'m working on some Javascript code that creates an alpha mask of a image using paths embedded by Photoshop. The onload handler of a IMG tag would call a clip(this). The functi

相关标签:
2条回答
  • 2021-01-31 19:47

    I had same issue while playing with pdf.js library, and solution I found is to make my own Uint8Array, below is code which you need. All credits goes to notmasteryet@github and full code can be found here https://gist.github.com/1057924

    (function() {
      try {
        var a = new Uint8Array(1);
        return; //no need
      } catch(e) { }
    
      function subarray(start, end) {
        return this.slice(start, end);
      }
    
      function set_(array, offset) {
        if (arguments.length < 2) offset = 0;
        for (var i = 0, n = array.length; i < n; ++i, ++offset)
          this[offset] = array[i] & 0xFF;
      }
    
      // we need typed arrays
      function TypedArray(arg1) {
        var result;
        if (typeof arg1 === "number") {
           result = new Array(arg1);
           for (var i = 0; i < arg1; ++i)
             result[i] = 0;
        } else
           result = arg1.slice(0);
        result.subarray = subarray;
        result.buffer = result;
        result.byteLength = result.length;
        result.set = set_;
        if (typeof arg1 === "object" && arg1.buffer)
          result.buffer = arg1.buffer;
    
        return result;
      }
    
      window.Uint8Array = TypedArray;
      window.Uint32Array = TypedArray;
      window.Int32Array = TypedArray;
    })();
    
    0 讨论(0)
  • 2021-01-31 19:52

    If you want to be assured you get wider range of compatibility, you can also use the compatibility.js file included in the PDF.js distribution under the "web" directory. Get PDF.js from Mozilla Github, decompress the zip archive and include the compatibility.js file from the above directory. It also makes PDF.js library work in e.g. IE9

    0 讨论(0)
提交回复
热议问题