- Catalog packs: the build emits /data/pack/manifest-v1.json plus content-hashed deflate-raw packs (columns + dictionaries); the site and the apps read them (about 264 KB on a first visit instead of about 520 KB of JSON). Descriptions live in their own packs and load on demand (a game page: its chunk; a search: all of them). - The IndexedDB cache is stored as compressed bytes by a small binary persister (replaces @tanstack/query-async-storage-persister); fflate is the lazy fallback where the browser has no Compression Streams. - The readable /data/*.json goes only to apps 4.0-4.1.1 (Tauri Origin); everyone else gets a 410 with links to the repository (worker/legacy-data.ts, five positive run_worker_first entries). - /img: exact width strings only, fallback originals and missing images kept at the edge for a day, failed background puts are logged. - Themed scrollbars and a "Hide scrollbars" setting (Settings and the display menu); chart cards no longer block their list scrollbars. - Policies (LEGAL_VERSION 2026-10-03): data reuse goes through the repository. Docs, changelog and version 4.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
/**
|
||
* deflate-raw in both directions, for the catalog packs and the IndexedDB
|
||
* cache. Uses the browser's Compression Streams when they know the format,
|
||
* else fflate, loaded on demand (Safari / iOS 15.4–16.3, older WebViews).
|
||
*/
|
||
type Bytes = Uint8Array<ArrayBuffer>
|
||
type Codec = { readable: ReadableStream<Uint8Array>; writable: WritableStream<Uint8Array> }
|
||
|
||
// Feed big inputs in slices so the page keeps responding between them.
|
||
const SLICE = 256 * 1024
|
||
|
||
function nativeCodec(kind: 'inflate' | 'deflate'): Codec | null {
|
||
try {
|
||
// Throws where the API is missing (ReferenceError) or 'deflate-raw' isn't known (TypeError).
|
||
const codec = kind === 'inflate' ? new DecompressionStream('deflate-raw') : new CompressionStream('deflate-raw')
|
||
return codec as unknown as Codec
|
||
} catch {
|
||
return null
|
||
}
|
||
}
|
||
|
||
async function run(codec: Codec, bytes: Bytes): Promise<Bytes> {
|
||
const writer = codec.writable.getWriter()
|
||
const writing = (async () => {
|
||
for (let at = 0; at < bytes.length; at += SLICE) await writer.write(bytes.subarray(at, at + SLICE))
|
||
await writer.close()
|
||
})()
|
||
const [out] = await Promise.all([new Response(codec.readable).arrayBuffer(), writing])
|
||
return new Uint8Array(out)
|
||
}
|
||
|
||
export async function inflateRaw(bytes: Bytes): Promise<Bytes> {
|
||
const codec = nativeCodec('inflate')
|
||
if (codec) return run(codec, bytes)
|
||
const { inflateSync } = await import('fflate')
|
||
return inflateSync(bytes) as Bytes
|
||
}
|
||
|
||
/** `fallbackLevel` applies to fflate only, which blocks the main thread while it works. */
|
||
export async function deflateRaw(bytes: Bytes, fallbackLevel: 1 | 3 | 6 | 9 = 6): Promise<Bytes> {
|
||
const codec = nativeCodec('deflate')
|
||
if (codec) return run(codec, bytes)
|
||
const { deflateSync } = await import('fflate')
|
||
return deflateSync(bytes, { level: fallbackLevel }) as Bytes
|
||
}
|