/** * @ignore */ export const base64ToBlob = (base64: string): Blob => { const base64Parts = base64.split(','); if (base64Parts.length < 2) { throw new Error('Invalid base64 string'); } // Decode base64 to binary string const byteString: string = atob(base64Parts[1]!); // Extract the mime type from the base64 header const mimeString: string = base64Parts[0]!.split(':')[1]!.split(';')[0]!; // Create a Uint8Array from the binary string const byteArray: Uint8Array = new Uint8Array(byteString.length); for (let i = 0; i < byteString.length; i++) { byteArray[i] = byteString.charCodeAt(i); } // Return the Blob object return new Blob([byteArray], { type: mimeString }); };