Created
April 9, 2015 07:48
-
-
Save karlwestin/a9c41e657b203b3f185d to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* | |
* Just a copy/pasted function | |
* to save base64 encoded data to a buffer | |
* http://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript | |
* | |
*/ | |
angular.module('eha.biometricregistration') | |
.factory('base64ToBuffer', function($window) { | |
return function b64toBlob(b64Data, contentType, sliceSize) { | |
contentType = contentType || ''; | |
sliceSize = sliceSize || 512; | |
var byteCharacters = atob(b64Data); | |
var byteArrays = []; | |
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) { | |
var slice = byteCharacters.slice(offset, offset + sliceSize); | |
var byteNumbers = new Array(slice.length); | |
for (var i = 0; i < slice.length; i++) { | |
byteNumbers[i] = slice.charCodeAt(i); | |
} | |
var byteArray = new Uint8Array(byteNumbers); | |
byteArrays.push(byteArray); | |
} | |
var blob = new Blob(byteArrays, {type: contentType}); | |
return blob; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment