MCPcopy Create free account
hub / github.com/scriptscat/scriptcat / uint8ToBase64

Function uint8ToBase64

src/pkg/utils/datatype.ts:34–52  ·  view source on GitHub ↗
(uint8arr: Uint8Array<ArrayBufferLike>)

Source from the content-addressed store, hash-verified

32}
33
34export function uint8ToBase64(uint8arr: Uint8Array<ArrayBufferLike>): string {
35 if (typeof (uint8arr as any).toBase64 === "function") {
36 // JS 2025
37 return (uint8arr as any).toBase64() as string;
38 } else if (typeof Buffer !== "undefined" && typeof Buffer.from === "function") {
39 // Node.js
40 return Buffer.from(uint8arr).toString("base64") as string;
41 } else {
42 // Fallback
43 let binary = "";
44 let i = 0;
45 while (uint8arr.length - i > 65535) {
46 binary += String.fromCharCode(...uint8arr.slice(i, i + 65535));
47 i += 65535;
48 }
49 binary += String.fromCharCode(...(i ? uint8arr.slice(i) : uint8arr));
50 return btoa(binary) as string;
51 }
52}
53
54// Split Uint8Array (or ArrayBuffer) into 2MB chunks as Uint8Array views
55export function chunkUint8(src: Uint8Array | ArrayBuffer, chunkSize = 2 * 1024 * 1024): Uint8Array<ArrayBufferLike>[] {

Callers 2

BgGMXhrClass · 0.90
dataEncodeFunction · 0.90

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected