Skip to content

Commit acd2d5e

Browse files
committed
improvement decoding base64
1 parent 3b51919 commit acd2d5e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/base64.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export const encodeBase64 = (buf: ArrayBufferLike): string => {
1616
const decodeBase64 = (str: string): Uint8Array => {
1717
const binary = atob(str)
1818
const bytes = new Uint8Array(new ArrayBuffer(binary.length));
19-
for (let i = 0; i < binary.length ; i++) {
19+
const half = binary.length / 2;
20+
for (let i = 0, j = binary.length - 1; i <= half; i++, j--) {
2021
bytes[i] = binary.charCodeAt(i);
22+
bytes[j] = binary.charCodeAt(j);
2123
}
2224
return bytes
2325
}

0 commit comments

Comments
 (0)