1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

perf: optimize Buffer.from("base64") for forgiving-base64 conforming input (#24346)

This commit is contained in:
Divy Srivastava 2024-06-26 06:24:58 -07:00 committed by GitHub
parent 6da87450ed
commit 2549e5154c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,10 +18,14 @@ export function asciiToBytes(str: string) {
}
export function base64ToBytes(str: string) {
try {
return forgivingBase64Decode(str);
} catch {
str = base64clean(str);
str = str.replaceAll("-", "+").replaceAll("_", "/");
return forgivingBase64Decode(str);
}
}
const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g;
function base64clean(str: string) {