File size: 533 Bytes
d0d7bbe
c1f12bf
d0d7bbe
 
c1f12bf
 
 
 
 
 
d0d7bbe
 
c1f12bf
d0d7bbe
 
c1f12bf
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
export function base64DataUriToBlob(dataURI: string) {
  dataURI = dataURI.replace(/^data:/, '')

  const match = dataURI.match(/(?:image|video|audio|text)\/[^;]+/)
  const type = match?.[0] || ''
  const base64 = Buffer.from(dataURI.replace(/^[^,]+,/, ''), 'base64').toString(
    'binary'
  )
  const arrayBuffer = new ArrayBuffer(base64.length)
  const typedArray = new Uint8Array(arrayBuffer)

  for (let i = 0; i < base64.length; i++) {
    typedArray[i] = base64.charCodeAt(i)
  }

  return new Blob([arrayBuffer], { type })
}