Skip to content

Commit

Permalink
chore: remove IE polyfill for ArrayBuffer.slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-John Lange authored and janl committed Jun 18, 2024
1 parent 8739f80 commit 9a9ff27
Showing 1 changed file with 8 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
function cloneArrayBuffer(buff) {
if (typeof buff.slice === 'function') {
return buff.slice(0);
}
// IE10-11 slice() polyfill
var target = new ArrayBuffer(buff.byteLength);
var targetArray = new Uint8Array(target);
var sourceArray = new Uint8Array(buff);
targetArray.set(sourceArray);
return target;
}

/**
* @template {ArrayBuffer | Blob} T
* @param {T} object
* @returns {T}
*/
function cloneBinaryObject(object) {
if (object instanceof ArrayBuffer) {
return cloneArrayBuffer(object);
}
// Blob
return object.slice(0, object.size, object.type);
return object instanceof ArrayBuffer
? object.slice(0)
: object.slice(0, object.size, object.type);
}

export default cloneBinaryObject;

0 comments on commit 9a9ff27

Please sign in to comment.