Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Created October 2, 2014 23:14
Show Gist options
  • Save meandavejustice/d21448317dc6b8a822cd to your computer and use it in GitHub Desktop.
Save meandavejustice/d21448317dc6b8a822cd to your computer and use it in GitHub Desktop.
function _base64toArrayBuffer(base64) {
var binary_string = window.atob(base64);
var len = binary_string.length;
var bytes = new Uint8Array( len );
for (var i = 0; i < len; i++) {
var ascii = binary_string.charCodeAt(i);
bytes[i] = ascii;
}
return bytes.buffer;
}
function genURL(key, cb) {
orm.get(key, function(err, data) {
if (err) cb(err);
var arrBuffer = _base64toArrayBuffer(data.base64);
var blob = new Blob([arrBuffer], {type: data.type});
var url = URL.createObjectURL(blob);
cb(null, url);
})
}
module.exports = genURL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment