MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / blobToUint8Array

Function blobToUint8Array

src/pkg/utils/datatype.ts:4–14  ·  view source on GitHub ↗
(blob: Blob)

Source from the content-addressed store, hash-verified

2
3/** Convert a Blob/File to Uint8Array */
4export 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) */
17export function base64ToUint8(b64: string): Uint8Array<ArrayBuffer> {

Callers 1

Calls 1

arrayBufferMethod · 0.45

Tested by

no test coverage detected