nolanlawson / blob-util

Cross-browser utils for working with binary Blobs
https://nolanlawson.github.io/blob-util
Apache License 2.0
503 stars 45 forks source link

dataUrlToBlob ignores type parameters and assumes base64-encoding #62

Open Treora opened 4 years ago

Treora commented 4 years ago

As remarked in #61:

a quick look at this library’s dataUrlToBlob() implementation reveals however that it throws away all of the media type parameters! And blindly assumes base64 encoding.

Current implementation:

export function dataURLToBlob (dataURL: string): Blob {
  var type = dataURL.match(/data:([^;]+)/)[1]
  var base64 = dataURL.replace(/^[^,]+,/, '')

  var buff = binaryStringToArrayBuffer(atob(base64))
  return createBlob([buff], { type: type })
}

Issues:

nolanlawson commented 3 years ago

Yep, this is true! I assumed base64 encoding for data URLs (for both input and output).