Files
website/node_modules/pagefind/lib/encoding.js
2024-05-06 17:15:30 -04:00

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;
};