Open History to see the last commit
1import type { PreviewPassword, PreviewUnlock } from "./previewUnlock";
2import type { PreviewFailure } from "./previewFailure";
3import { ARCHIVE_MAX_BYTES } from "@t3tools/client-runtime/zip/bounded-zip";
4
5export {
6 ARCHIVE_ENTRY_MAX_BYTES,
7 ARCHIVE_MAX_ENTRIES,
8 ARCHIVE_MAX_RATIO,
9} from "@t3tools/client-runtime/zip/bounded-zip";
10export const BINARY_PREVIEW_MAX_BYTES = ARCHIVE_MAX_BYTES;
11export const SQLITE_PAGE_SIZE = 50;
12
13export function formatArchiveModifiedDate(
14 modified: string | null,
15 locales?: Intl.LocalesArgument,
16): string {
17 if (!modified) return "-";
18 // ZIP times are zone-less wall-clock (no "Z"); formatting them in UTC keeps their calendar
19 // date even when the viewer's zone skips that hour for daylight saving time.
20 const wallClock = !modified.endsWith("Z");
21 const date = new Date(wallClock ? `${modified}Z` : modified);
22 if (Number.isNaN(date.getTime())) return "-";
23 return date.toLocaleDateString(locales, wallClock ? { timeZone: "UTC" } : undefined);
24}
25
26export interface ArchiveEntry {
27 path: string;
28 size: number;
29 modified: string | null;
30 directory: boolean;
31 /** Where a symbolic link points, when the format records it. */
32 link?: string;
33}
34
35type ArchiveRowOrder = Pick<ArchiveEntry, "path" | "directory">;
36let archiveNameCollator: Intl.Collator | undefined;
37
38export function compareArchiveRows(a: ArchiveRowOrder, b: ArchiveRowOrder): number {
39 if (a.directory !== b.directory) return a.directory ? -1 : 1;
40 archiveNameCollator ??= new Intl.Collator(undefined, { numeric: true, sensitivity: "base" });
41 return archiveNameCollator.compare(a.path, b.path);
42}
43
44export type BinaryWorkerRequest =
45 | PreviewUnlock
46 | { type: "open"; kind: "archive" | "sqlite"; name: string; bytes: ArrayBuffer }
47 /** Disk images run to gigabytes, so the worker reads only the ranges it needs. */
48 | { type: "open"; kind: "archive"; name: string; src: string }
49 | { type: "entry"; path: string }
50 | { type: "rows"; table: string; page: number };
51
52export type BinaryWorkerResult =
53 | PreviewPassword
54 | ({ type: "error" } & PreviewFailure)
55 | { type: "archive"; entries: ArchiveEntry[]; volume?: string; sizeBytes?: number }
56 | { type: "entry"; path: string; bytes: Uint8Array<ArrayBuffer> }
57 | { type: "sqlite"; tables: { name: string; count: number }[] }
58 | { type: "rows"; table: string; page: number; columns: string[]; rows: string[][] };