Simplified urlBase64ToUint8Array

This commit is contained in:
Eduard Urbach 2019-05-26 11:56:41 +09:00
parent 776d865fd7
commit 3094434326
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -100,18 +100,12 @@ export default class PushManager {
} }
} }
function urlBase64ToUint8Array(base64String) { function urlBase64ToUint8Array(base64String: string) {
const padding = "=".repeat((4 - base64String.length % 4) % 4) const padding = "=".repeat((4 - base64String.length % 4) % 4)
const base64 = (base64String + padding) const base64 = (base64String + padding)
.replace(/\-/g, "+") .replace(/\-/g, "+")
.replace(/_/g, "/") .replace(/_/g, "/")
const rawData = window.atob(base64) const rawData = window.atob(base64)
const outputArray = new Uint8Array(rawData.length) return Uint8Array.from([...rawData].map(char => char.charCodeAt(0)))
for(let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i)
}
return outputArray
} }