Skip to content

Commit bf96993

Browse files
committed
use direct string instead of base64 for ArrayBuffer
1 parent 243bd6b commit bf96993

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/seriall/builtin/adapters.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,23 +84,22 @@ export const BUILTIN_ADAPTERS: ContextAdapters = new Map([
8484
serialize: (obj: ArrayBuffer) => {
8585
const arr = new Uint8Array(obj);
8686
const chunkSize = 32768;
87-
let bin = '';
87+
let bytes = '';
8888

8989
for (let i = 0; i < arr.length; i += chunkSize) {
9090
const chunk = arr.subarray(i, i + chunkSize);
91-
bin += String.fromCharCode.apply(
91+
bytes += String.fromCharCode.apply(
9292
null,
9393
chunk as unknown as number[],
9494
);
9595
}
9696

97-
return btoa(bin);
97+
return bytes;
9898
},
9999
deserialize: (pure: string) => {
100-
const bin = atob(pure);
101-
const arr = new Uint8Array(bin.length);
102-
for (let i = 0; i < bin.length; i++) {
103-
arr[i] = bin.charCodeAt(i);
100+
const arr = new Uint8Array(pure.length);
101+
for (let i = 0; i < pure.length; i++) {
102+
arr[i] = pure.charCodeAt(i);
104103
}
105104
return arr.buffer;
106105
},

0 commit comments

Comments
 (0)