-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompat.js
More file actions
145 lines (134 loc) · 4.9 KB
/
Copy pathcompat.js
File metadata and controls
145 lines (134 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
(function () {
var typedArrays = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array];
if (window.Float64Array) {
typedArrays.push(Float64Array);
}
// fix for webkit pre slice rename
if (!Float32Array.prototype.subarray) {
typedArrays.forEach(function (cls) {
cls.prototype.subarray = cls.prototype.slice;
});
}
// fix for https://bugzilla.mozilla.org/show_bug.cgi?id=637643
else if (new Int8Array([0, 1, 0]).subarray(1).subarray(1)[0]) {
function subarray (begin, end) {
if (arguments.length === 0) {
// duplicate the array
return new this.constructor(this.buffer, this.byteOffset, this.length);
}
else {
if (begin < 0) {
// relative to end
begin += this.length;
}
// clamp to 0, length
begin = Math.max(0, Math.min(this.length, begin));
if (arguments.length < 2) {
// slice to end
end = this.length;
}
else {
if (end < 0) {
// relative to end
end += this.length;
}
// clamp to begin, length
end = Math.max(begin, Math.min(this.length, end));
}
var byteOffset = this.byteOffset + begin * this.BYTES_PER_ELEMENT;
return new this.constructor(this.buffer, byteOffset, end - begin);
}
}
typedArrays.forEach(function (cls) {
cls.prototype.subarray = subarray;
});
}
if (!FileReader.prototype.readAsArrayBuffer) {
FileReader.prototype.readAsArrayBuffer = function readAsArrayBuffer () {
this.readAsBinaryString.apply(this, arguments);
this.__defineGetter__('resultString', this.__lookupGetter__('result'));
this.__defineGetter__('result', function () {
var string = this.resultString;
var result = new Uint8Array(string.length);
for (var i = 0; i < string.length; i++) {
result[i] = string.charCodeAt(i);
}
return result.buffer;
});
};
}
if (!window.DataView) {
function DataView(buffer) {
this.buffer = buffer;
}
// DataView polyfill
DataView.prototype = {
get: function (cls, byteOffset, littleEndian) {
var buffer;
if (!littleEndian) {
var sourceChars = new Uint8Array(this.buffer, byteOffset, cls.BYTES_PER_ELEMENT);
var destChars = new Uint8Array(cls.BYTES_PER_ELEMENT);
if (cls.BYTES_PER_ELEMENT === 2) {
destChars[0] = sourceChars[1];
destChars[1] = sourceChars[0];
}
else if (cls.BYTES_PER_ELEMENT === 4) {
destChars[0] = sourceChars[3];
destChars[1] = sourceChars[2];
destChars[2] = sourceChars[1];
destChars[3] = sourceChars[0];
}
else if (cls.BYTES_PER_ELEMENT === 8) {
destChars[0] = sourceChars[7];
destChars[1] = sourceChars[6];
destChars[2] = sourceChars[5];
destChars[3] = sourceChars[4];
destChars[4] = sourceChars[3];
destChars[5] = sourceChars[2];
destChars[6] = sourceChars[1];
destChars[7] = sourceChars[0];
}
buffer = destChars.buffer;
}
else if (byteOffset % cls.BYTES_PER_ELEMENT) {
var sourceChars = new Uint8Array(this.buffer, byteOffset, cls.BYTES_PER_ELEMENT);
var destChars = new Uint8Array(cls.BYTES_PER_ELEMENT);
destChars.set(sourceChars);
buffer = destChars.buffer;
}
else {
buffer = this.buffer
}
return new cls(buffer, 0, 1)[0];
},
getUint32: function (byteOffset, littleEndian) {
return this.get(Uint32Array, byteOffset, littleEndian);
},
getUint16: function (byteOffset, littleEndian) {
return this.get(Uint16Array, byteOffset, littleEndian);
},
getUint8: function (byteOffset) {
return new Uint8Array(this.buffer, byteOffset, 1)[0];
}
};
window.DataView = DataView;
}
// TODO opera?
var slice = Blob.prototype.webkitSlice || Blob.prototype.mozSlice;
if (!slice) {
if (window.BlobBuilder) {
var bb = new BlobBuilder();
bb.append("abcd");
if (bb.getBlob().slice(2, 2).size !== 2) {
slice = Blob.prototype.slice;
}
}
if (!slice) {
var origSlice = Blob.prototype.slice;
slice = function slice(start, end) {
return origSlice.apply(this, [start, end - start]);
};
}
}
Blob.prototype.slice = slice;
})();