Skip to content

Instantly share code, notes, and snippets.

@hanayashiki
Created December 16, 2019 04:08
Show Gist options
  • Save hanayashiki/8dac237671343e7f0b15de617b0051bd to your computer and use it in GitHub Desktop.
Save hanayashiki/8dac237671343e7f0b15de617b0051bd to your computer and use it in GitHub Desktop.
Safari 13.0.4: Blob.arrayBuffer is not a function
(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
@RamBoFe
Copy link

RamBoFe commented Jul 13, 2022

Thanks !!!!!! I use it in my unit tests with jest !

@manduriomane
Copy link

Thanks a lot!!!! It works fine!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment