Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

perf(desktop): avoid quadratic string concat in encodeFileAsBase64

Richie McIlroyfc691e867327
diff --git a/apps/desktop/src/utils/organization-branding.ts b/apps/desktop/src/utils/organization-branding.ts
index 38d9fe88e..0356f6024 100644
--- a/apps/desktop/src/utils/organization-branding.ts
+++ b/apps/desktop/src/utils/organization-branding.ts
@@ -382,13 +382,15 @@ export function createSelectedOrganization() {
export async function encodeFileAsBase64(file: File) {
const bytes = new Uint8Array(await file.arrayBuffer());
const chunkSize = 0x8000;
- let binary = "";
+ const chunks: string[] = [];
for (let index = 0; index < bytes.length; index += chunkSize) {
- binary += String.fromCharCode(...bytes.subarray(index, index + chunkSize));
+ chunks.push(
+ String.fromCharCode(...bytes.subarray(index, index + chunkSize)),
+ );
}
- return btoa(binary);
+ return btoa(chunks.join(""));
}
function getResponseError(body: unknown) {