Changed blob to buffer fallback

This commit is contained in:
Mitchell McCaffrey 2020-05-08 19:28:15 +10:00
parent e73f64a3b5
commit dd13208424

View File

@ -3,8 +3,21 @@ async function blobToBuffer(blob) {
const arrayBuffer = await blob.arrayBuffer();
return new Uint8Array(arrayBuffer);
} else {
const arrayBuffer = new Response(blob).arrayBuffer();
return new Uint8Array(arrayBuffer);
return new Promise((resolve, reject) => {
const reader = new FileReader();
function onLoadEnd(event) {
reader.removeEventListener("loadend", onLoadEnd, false);
if (event.error) {
reject(event.error);
} else {
resolve(Buffer.from(reader.result));
}
}
reader.addEventListener("loadend", onLoadEnd, false);
reader.readAsArrayBuffer(blob);
});
}
}