MCPcopy Create free account
hub / github.com/Ptechgithub/configs / base64ToArrayBuffer

Function base64ToArrayBuffer

worker.js:577–590  ·  view source on GitHub ↗

* Decodes a base64 string into an ArrayBuffer. * @param {string} base64Str The base64 string to decode. * @returns {{earlyData: ArrayBuffer|null, error: Error|null}} An object containing the decoded ArrayBuffer or null if there was an error, and any error that occurred during decoding or null if t

(base64Str)

Source from the content-addressed store, hash-verified

575 * @returns {{earlyData: ArrayBuffer|null, error: Error|null}} An object containing the decoded ArrayBuffer or null if there was an error, and any error that occurred during decoding or null if there was no error.
576 */
577function base64ToArrayBuffer(base64Str) {
578 if (!base64Str) {
579 return { earlyData: null, error: null };
580 }
581 try {
582 // go use modified Base64 for URL rfc4648 which js atob not support
583 base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
584 const decode = atob(base64Str);
585 const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0));
586 return { earlyData: arryBuffer.buffer, error: null };
587 } catch (error) {
588 return { earlyData: null, error };
589 }
590}
591
592/**
593 * Checks if a given string is a valid UUID.

Callers 1

startFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected