mirror of
https://github.com/sern-handler/website
synced 2026-06-26 09:42:24 +00:00
28 lines
661 B
JavaScript
28 lines
661 B
JavaScript
/**
|
|
*
|
|
* @param {string} b64
|
|
* @returns {Uint8Array}
|
|
*/
|
|
export const decode = (b64) => {
|
|
let binString;
|
|
if (typeof Buffer !== "undefined" && typeof Buffer.from === "function") {
|
|
return Buffer.from(b64, "base64");
|
|
} else if (
|
|
typeof window !== "undefined" &&
|
|
typeof window.atob === "function"
|
|
) {
|
|
binString = window.atob(b64);
|
|
} else if (typeof atob === "function") {
|
|
binString = atob(b64);
|
|
} else {
|
|
throw new Error("Unable to decode base64 data");
|
|
}
|
|
|
|
const size = binString.length;
|
|
const bytes = new Uint8Array(size);
|
|
for (let i = 0; i < size; i++) {
|
|
bytes[i] = binString.charCodeAt(i);
|
|
}
|
|
return bytes;
|
|
};
|