Created
June 13, 2017 07:45
-
-
Save kapad/5b93b14f8a8b193745807b969b189489 to your computer and use it in GitHub Desktop.
Convert a base64 encoded data URI to binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let convertDataURIToBinary = (dataURI) => { | |
var BASE64_MARKER = ';base64,'; | |
var base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length; | |
var base64 = dataURI.substring(base64Index); | |
var raw = window.atob(base64); | |
var rawLength = raw.length; | |
var array = new Uint8Array(new ArrayBuffer(rawLength)); | |
for(var i = 0; i < rawLength; i++) { | |
array[i] = raw.charCodeAt(i); | |
} | |
return array; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment