Skip to content

Commit

Permalink
Merge branch 'release/v0.25.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
holtwick committed Oct 29, 2024
2 parents 290d9fa + 14b192b commit 5087975
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeed",
"type": "module",
"version": "0.25.5",
"version": "0.25.6",
"description": "🌱 Simple foundation library",
"author": {
"name": "Dirk Holtwick",
Expand Down
35 changes: 19 additions & 16 deletions src/common/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,25 @@ export function bitfield(bitfield = 0) {
// Cast

export async function blobToArrayBuffer(blob: Blob | File): Promise<ArrayBuffer | undefined> {
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<Uint8Array | undefined> {
Expand Down
3 changes: 2 additions & 1 deletion src/common/data/datauri.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { blobToArrayBuffer } from '../bin'
import { fromBase64, toBase64 } from './bin'

export function dataUriToUint8Array(dataUri: string): Uint8Array | undefined {
Expand All @@ -18,7 +19,7 @@ export function dataUriToBlob(dataUri: string): Blob | undefined {
}

export async function blobToDataUri(blob: Blob): Promise<string | undefined> {
const bin = await blob.arrayBuffer()
const bin = await blobToArrayBuffer(blob)
if (bin)
return `data:${blob.type},${toBase64(bin)}`
}
Expand Down

0 comments on commit 5087975

Please sign in to comment.