Created
December 16, 2019 04:08
-
-
Save hanayashiki/8dac237671343e7f0b15de617b0051bd to your computer and use it in GitHub Desktop.
Safari 13.0.4: Blob.arrayBuffer is not a function
This file contains 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 () { | |
File.prototype.arrayBuffer = File.prototype.arrayBuffer || myArrayBuffer; | |
Blob.prototype.arrayBuffer = Blob.prototype.arrayBuffer || myArrayBuffer; | |
function myArrayBuffer() { | |
// this: File or Blob | |
return new Promise((resolve) => { | |
let fr = new FileReader(); | |
fr.onload = () => { | |
resolve(fr.result); | |
}; | |
fr.readAsArrayBuffer(this); | |
}) | |
} | |
})(); | |
// This is a simple trick to implement Blob.arrayBuffer (https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer) using FileReader |
Thanks a lot!!!! It works fine!!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks !!!!!! I use it in my unit tests with jest !