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:
parent
6da87450ed
commit
2549e5154c
1 changed files with 7 additions and 3 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue