-
-
Save Jae-kwang/079c31fc1685f6ae85e0e0fc6604dce7 to your computer and use it in GitHub Desktop.
Uint8Array Support for IE8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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; | |
})(); | |
(function() { | |
if ("response" in XMLHttpRequest.prototype || | |
"mozResponseArrayBuffer" in XMLHttpRequest.prototype || | |
"mozResponse" in XMLHttpRequest.prototype || | |
"responseArrayBuffer" in XMLHttpRequest.prototype) | |
return; | |
Object.defineProperty(XMLHttpRequest.prototype, "response", { | |
get: function() { | |
return new Uint8Array( new VBArray(this.responseBody).toArray() ); | |
} | |
}); | |
})(); | |
(function() { | |
if ("btoa" in window) | |
return; | |
var digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
window.btoa = function(chars) { | |
var buffer = ""; | |
var i, n; | |
for (i = 0, n = chars.length; i < n; i += 3) { | |
var b1 = chars.charCodeAt(i) & 0xFF; | |
var b2 = chars.charCodeAt(i + 1) & 0xFF; | |
var b3 = chars.charCodeAt(i + 2) & 0xFF; | |
var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4); | |
var d3 = i + 1 < n ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64; | |
var d4 = i + 2 < n ? (b3 & 0x3F) : 64; | |
buffer += digits.charAt(d1) + digits.charAt(d2) + digits.charAt(d3) + digits.charAt(d4); | |
} | |
return buffer; | |
}; | |
})(); |
Hello! I imported your package and did not cover the Unit32Array of the current window.
In IE11 IE8 document mode browser prompts UintArray is not defined
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
socket-io-client에서 IE9에서 미지원하는 Uint8Array 를 사용하는 문제를 해결하기 위한 hack