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 for this!
This is awesome! You saved me!
Amazing! For some reason Babel doesn't seem to be able to generate this right now. Those guys should add this polyfill for Safari.
clutch
Thanks !!!!!! I use it in my unit tests with jest !
Thanks a lot!!!! It works fine!!!!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh thank you for advice