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,9 +18,13 @@ 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;