(blob: Blob)
| 2 | |
| 3 | /** Convert a Blob/File to Uint8Array */ |
| 4 | export const blobToUint8Array = async (blob: Blob): Promise<Uint8Array<ArrayBuffer>> => { |
| 5 | if (typeof blob?.arrayBuffer === "function") return new Uint8Array(await blob.arrayBuffer()); |
| 6 | return new Promise((resolve, reject) => { |
| 7 | const reader = new FileReader(); |
| 8 | reader.onloadend = function () { |
| 9 | resolve(new Uint8Array(this.result as ArrayBuffer)); |
| 10 | }; |
| 11 | reader.onerror = reject; |
| 12 | reader.readAsArrayBuffer(blob); |
| 13 | }); |
| 14 | }; |
| 15 | |
| 16 | /** Base64 -> Uint8Array (browser-safe) */ |
| 17 | export function base64ToUint8(b64: string): Uint8Array<ArrayBuffer> { |
no test coverage detected