feat(export): PDF and EPUB export with save dialog

This commit is contained in:
pj committed 2026-06-20 13:02:30 -04:00
1 parent da94acc0ec
commit e424008d56
2 files changed
+38

No files matched your search

+19
View File
@@ -18,3 +18,22 @@ export async function openBook(): Promise<{ book: Book; path: string } | null> {
const contents = await invoke<string>("read_file", { path: selected });
return { book: JSON.parse(contents) as Book, path: selected };
}
function toBase64(bytes: Uint8Array): string {
let binary = "";
const chunk = 0x8000;
for (let i = 0; i < bytes.length; i += chunk) {
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
}
return btoa(binary);
}
export async function saveBytes(
bytes: Uint8Array,
defaultName: string,
filters: { name: string; extensions: string[] }[]
): Promise<void> {
const path = await save({ filters, defaultPath: defaultName });
if (!path) return;
await invoke("write_bytes", { path, data: toBase64(bytes) });
}