Skip to content

Commit 6cae752

Browse files
Phillip9587Copilot
andcommitted
switch implementations based on benchmarks
Co-authored-by: Copilot <[email protected]>
1 parent c55777b commit 6cae752

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,17 @@ const textDecoder = new TextDecoder('utf-8');
119119
* @private
120120
*/
121121
const decodeBase64: (str: string) => string = (() => {
122-
// 1) Modern Web / some runtimes
122+
// 1) Node.js (fast path)
123+
if (typeof NodeBuffer?.from === 'function') {
124+
return (str: string) => NodeBuffer.from(str, 'base64').toString('utf-8');
125+
}
126+
127+
// 2) Modern Web / some runtimes
123128
if (typeof (Uint8Array as Uint8ArrayWithBase64).fromBase64 === 'function') {
124129
return (str: string) =>
125130
textDecoder.decode((Uint8Array as Uint8ArrayWithBase64).fromBase64!(str));
126131
}
127132

128-
// 2) Node.js (fast path)
129-
if (typeof NodeBuffer?.from === 'function') {
130-
return (str: string) => NodeBuffer.from(str, 'base64').toString('utf-8');
131-
}
132-
133133
// 3) Browser fallback
134134
return (str: string) => {
135135
const binary = atob(str);

0 commit comments

Comments
 (0)