mirror of
https://github.com/xCyanGrizzly/DragonsStash.git
synced 2026-09-21 13:31:42 +00:00
feat(worker): CRC32 archive fingerprint compare
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { FileEntry } from "./zip-reader.js";
|
||||
|
||||
export function crcFingerprint(entries: FileEntry[]): { crcs: string[]; complete: boolean } {
|
||||
if (entries.length === 0) return { crcs: [], complete: false };
|
||||
const crcs: string[] = [];
|
||||
let complete = true;
|
||||
for (const e of entries) {
|
||||
if (e.crc32 == null) { complete = false; continue; }
|
||||
crcs.push(e.crc32.toLowerCase());
|
||||
}
|
||||
crcs.sort();
|
||||
return { crcs, complete };
|
||||
}
|
||||
|
||||
export function fingerprintsMatch(a: FileEntry[], b: FileEntry[]): boolean {
|
||||
const fa = crcFingerprint(a);
|
||||
const fb = crcFingerprint(b);
|
||||
if (!fa.complete || !fb.complete) return false;
|
||||
if (fa.crcs.length !== fb.crcs.length) return false;
|
||||
return fa.crcs.every((c, i) => c === fb.crcs[i]);
|
||||
}
|
||||
Reference in New Issue
Block a user