From d4c9f3563410338059d7c20a0014cebc038ca8d4 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Tue, 29 Oct 2024 10:14:14 +0100 Subject: [PATCH 1/2] fix: blobToArrayBuffer --- src/common/bin/index.ts | 35 +++++++++++++++++++---------------- src/common/data/datauri.ts | 3 ++- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/common/bin/index.ts b/src/common/bin/index.ts index 2c1a954f..4ea94956 100644 --- a/src/common/bin/index.ts +++ b/src/common/bin/index.ts @@ -95,22 +95,25 @@ export function bitfield(bitfield = 0) { // Cast export async function blobToArrayBuffer(blob: Blob | File): Promise { - return await blob.arrayBuffer() - // try { - // return new Promise((resolve, reject) => { - // try { - // const reader = new FileReader() - // reader.onloadend = () => resolve(reader.result as ArrayBuffer) - // reader.onerror = err => reject(err) - // reader.onabort = err => reject(err) - // reader.readAsArrayBuffer(blob) - // } - // catch (err) { - // reject(err) - // } - // }) - // } - // catch (err) {} + if (blob.arrayBuffer) + return await blob.arrayBuffer() + + // Fallback for older browsers + try { + return new Promise((resolve, reject) => { + try { + const reader = new FileReader() + reader.onloadend = () => resolve(reader.result as ArrayBuffer) + reader.onerror = err => reject(err) + reader.onabort = err => reject(err) + reader.readAsArrayBuffer(blob) + } + catch (err) { + reject(err) + } + }) + } + catch (err) {} } export async function blobToUint8Array(blob: Blob | File): Promise { diff --git a/src/common/data/datauri.ts b/src/common/data/datauri.ts index aca62f57..67b01484 100644 --- a/src/common/data/datauri.ts +++ b/src/common/data/datauri.ts @@ -1,3 +1,4 @@ +import { blobToArrayBuffer } from '../bin' import { fromBase64, toBase64 } from './bin' export function dataUriToUint8Array(dataUri: string): Uint8Array | undefined { @@ -18,7 +19,7 @@ export function dataUriToBlob(dataUri: string): Blob | undefined { } export async function blobToDataUri(blob: Blob): Promise { - const bin = await blob.arrayBuffer() + const bin = await blobToArrayBuffer(blob) if (bin) return `data:${blob.type},${toBase64(bin)}` } From 14b192bb7db0074e91a50d75026e06b90a8094d5 Mon Sep 17 00:00:00 2001 From: Dirk Holtwick Date: Tue, 29 Oct 2024 10:14:16 +0100 Subject: [PATCH 2/2] 0.25.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6c10f89e..953487f8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zeed", "type": "module", - "version": "0.25.5", + "version": "0.25.6", "description": "🌱 Simple foundation library", "author": { "name": "Dirk Holtwick",