Skip to content

Commit 14fc0d3

Browse files
committed
Move buffer.slice polyfill into separate function.
1 parent 2b1bf2f commit 14fc0d3

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

js/load-image-meta.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
Blob.prototype.webkitSlice ||
3636
Blob.prototype.mozSlice)
3737

38+
loadImage.bufferSlice =
39+
loadImage.global.ArrayBuffer.prototype.slice ||
40+
function (begin, end) {
41+
// Polyfill for IE10, which does not support ArrayBuffer.slice
42+
// eslint-disable-next-line no-param-reassign
43+
end = end || this.byteLength - begin
44+
var arr1 = new Uint8Array(this, begin, end)
45+
var arr2 = new Uint8Array(end)
46+
arr2.set(arr1)
47+
return arr2.buffer
48+
}
49+
3850
loadImage.metaDataParsers = {
3951
jpeg: {
4052
0xffe1: [], // APP1 marker
@@ -89,8 +101,6 @@
89101
var markerLength
90102
var parsers
91103
var i
92-
var arr1
93-
var arr2
94104
// Check for the JPEG marker (0xffd8):
95105
if (dataView.getUint16(0) === 0xffd8) {
96106
while (offset < maxOffset) {
@@ -136,16 +146,7 @@
136146
// Meta length must be longer than JPEG marker (2)
137147
// plus APPn marker (2), followed by length bytes (2):
138148
if (!options.disableImageHead && headLength > 6) {
139-
if (buffer.slice) {
140-
data.imageHead = buffer.slice(0, headLength)
141-
} else {
142-
// Workaround for IE10, which does not support
143-
// ArrayBuffer.slice:
144-
arr1 = new Uint8Array(buffer, 0, headLength)
145-
arr2 = new Uint8Array(headLength)
146-
arr2.set(arr1)
147-
data.imageHead = arr2.buffer
148-
}
149+
data.imageHead = loadImage.bufferSlice.call(buffer, 0, headLength)
149150
}
150151
} else {
151152
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)