import { sha256 } from '@noble/hashes/sha2'; import { bytesToHex } from '@noble/hashes/utils'; /** * Compute a SHA-256 content hash for snapshot comparison. */ export function contentHash(content: string | Uint8Array): string { const bytes = typeof content === 'string' ? new TextEncoder().encode(content) : content; return `sha256:${bytesToHex(sha256(bytes))}`; } /** * Deep equality for file content (string vs Uint8Array). */ export function isContentEqual( a: string | Uint8Array, b: string | Uint8Array, ): boolean { if (typeof a === 'string' && typeof b === 'string') { return a === b; } if (a instanceof Uint8Array && b instanceof Uint8Array) { if (a.length !== b.length) return false; for (let i = 0; i < a.length; i++) { if (a[i] !== b[i]) return false; } return true; } return false; }