Skip to content

Instantly share code, notes, and snippets.

@leon0707
Created February 4, 2020 15:52
Show Gist options
  • Select an option

  • Save leon0707/399eabbf0c3319d17e1ef4932c966934 to your computer and use it in GitHub Desktop.

Select an option

Save leon0707/399eabbf0c3319d17e1ef4932c966934 to your computer and use it in GitHub Desktop.
urlBase64ToUint8Array
function urlBase64ToUint8Array(base64String) {
const padding = "=".repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, "+")
.replace(/_/g, "/");
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment