Skip to content

Commit

Permalink
made toBase64 function iterative instead of calling String.fromCharCo…
Browse files Browse the repository at this point in the history
…de.apply()
  • Loading branch information
kkmanos committed Dec 2, 2024
1 parent 1a2ed1d commit 2038f1f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ function toU8(b: BufferSource) {
}

export function toBase64(binary: BufferSource): string {
return btoa(String.fromCharCode.apply(String, toU8(binary)));
const uint8Array = toU8(binary);
const chunkSize = 0x8000; // 32KB
let result = '';
for (let i = 0; i < uint8Array.length; i += chunkSize) {
const chunk = uint8Array.subarray(i, i + chunkSize);
result += String.fromCharCode(...chunk);
}
return btoa(result);
}

export function toBase64Url(binary: BufferSource): string {
Expand Down

0 comments on commit 2038f1f

Please sign in to comment.