From dd13208424f8c22187a9f8c59279f48cec1b4460 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Fri, 8 May 2020 19:28:15 +1000 Subject: [PATCH] Changed blob to buffer fallback --- src/helpers/blobToBuffer.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/helpers/blobToBuffer.js b/src/helpers/blobToBuffer.js index c816ced..70e86af 100644 --- a/src/helpers/blobToBuffer.js +++ b/src/helpers/blobToBuffer.js @@ -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); + }); } }