Skip to content

Commit

Permalink
UI - Fix content page text loading (#377)
Browse files Browse the repository at this point in the history
* use TextDecoder utf-8 instead of fromCharCode

* add comment
  • Loading branch information
lucasjacks0n authored Feb 26, 2024
1 parent 3be92f8 commit 8fce4ac
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ui/src/routes/Namespace/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ const ContentPage = () => {
return new Blob([uint8Array]);
}

function bytesToString(bytes: number[]): string {
const chunkSize = 10000; // Size of each chunk, adjust based on your environment
function bytesToString(byteArray: number[]) {
const chunkSize = 10000;
const decoder = new TextDecoder("utf-8");
let result = "";

for (let i = 0; i < bytes.length; i += chunkSize) {
const chunk = bytes.slice(i, i + chunkSize);
result += String.fromCharCode.apply(null, chunk);
for (let i = 0; i < byteArray.length; i += chunkSize) {
const chunk = byteArray.slice(i, i + chunkSize);
result += decoder.decode(new Uint8Array(chunk), { stream: true });
}

// Decode any remaining parts of the byteArray
result += decoder.decode(); // Flush the decoder's state
return result;
}

Expand Down

0 comments on commit 8fce4ac

Please sign in to comment.