дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 01:31:41 +02:00
Pasting an image into a terminal or a Markdown file, or saving bytes from the UI, sent the data as a JSON array of numbers (3.6x the size), which Tauri and the remote server parse into a serde_json::Value first (~50x the bytes in memory: a 20 MB image took ~2.2 GB peak heap and 640 ms). Binary command arguments (fs_create_file_bytes, term_store_image) now travel as base64 text (IpcBytes): the same 20 MB takes ~112 MB and 32 ms. Native image drops reuse the base64 they already have. Co-authored-by: Mr0Bread <[email protected]>
21 рядки
835 B
TypeScript
21 рядки
835 B
TypeScript
import { expect, it } from "vitest";
|
|
import { toBase64 } from "./base64";
|
|
|
|
const decode = (text: string) => Uint8Array.from(atob(text), (c) => c.charCodeAt(0));
|
|
|
|
it("encodes every byte value and the empty input to standard padded base64", () => {
|
|
expect(toBase64(new Uint8Array())).toBe("");
|
|
expect(toBase64(new Uint8Array([0, 255]))).toBe("AP8=");
|
|
const all = Uint8Array.from({ length: 256 }, (_, i) => i);
|
|
expect([...decode(toBase64(all))]).toEqual([...all]);
|
|
});
|
|
|
|
it("is a string of at most ceil(4n/3) characters, across the chunk boundary", () => {
|
|
for (const n of [0x7fff, 0x8000, 0x8001, 5 * 0x8000 + 1]) {
|
|
const bytes = Uint8Array.from({ length: n }, (_, i) => (i * 31) % 256);
|
|
const text = toBase64(bytes);
|
|
expect(text).toHaveLength(4 * Math.ceil(n / 3));
|
|
expect(decode(text)).toEqual(bytes);
|
|
}
|
|
});
|