* 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
(base64Str)
| 651 | * @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. |
| 652 | */ |
| 653 | function base64ToArrayBuffer(base64Str) { |
| 654 | if (!base64Str) { |
| 655 | return { earlyData: null, error: null }; |
| 656 | } |
| 657 | try { |
| 658 | // go use modified Base64 for URL rfc4648 which js atob not support |
| 659 | base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/'); |
| 660 | const decode = atob(base64Str); |
| 661 | const arryBuffer = Uint8Array.from(decode, (c) => c.charCodeAt(0)); |
| 662 | return { earlyData: arryBuffer.buffer, error: null }; |
| 663 | } catch (error) { |
| 664 | return { earlyData: null, error }; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * Checks if a given string is a valid UUID. |