export const b64toBlob = (
  b64Data: string,
  contentType?: string,
  sliceSize?: number
): Blob => {
  b64Data = b64Data.replace(/^data:image\/[a-z]+;base64,/, "");
  const atob = require("atob");

  contentType = contentType || "image/jpeg";
  sliceSize = sliceSize || 512;

  let byteCharacters = atob(b64Data);
  let byteArrays = [];

  for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
    const slice = byteCharacters.slice(offset, offset + sliceSize);

    let byteNumbers = new Array(slice.length);
    for (let i = 0; i < slice.length; i++) {
      byteNumbers[i] = slice.charCodeAt(i);
    }

    const byteArray = new Uint8Array(byteNumbers);

    byteArrays.push(byteArray);
  }

  return new Blob(byteArrays, { type: contentType });
};
