DigestCachetypeno test imports ittype DigestCache = { get(key: string): Promise<string | undefined>; set(key: string, digest: string): Promise<void> };A place to keep the digest of a file by the store, the path and the revision it was read at.
How two files are compared: a ladder of comparators, each of which may decide or pass the pair to the next. The revisions decide where both stores name a file by the SHA-256 of its bytes; the size and the time decide only where the caller allows a weak answer; and the bytes, hashed, decide anything. What decided is kept with the action it led to, so that a plan says how it knows. The digest of a file is kept in a cache where the caller gives one, keyed by the store, the path and the revision, so that a file that has not changed is read once.
import { memoryDigestCache } from "./compare.ts";
const cache = memoryDigestCache();DigestCachetypeno test imports ittype DigestCache = { get(key: string): Promise<string | undefined>; set(key: string, digest: string): Promise<void> };A place to keep the digest of a file by the store, the path and the revision it was read at.
memoryDigestCachefunctionfunction memoryDigestCache(): DigestCacheA cache in memory.
Sidetypeno test imports ittype Side = { readonly store: Store<"read">; readonly stat: Stat };One file with the store it is in: what a comparison needs.
Verdicttypeno test imports ittype Verdict = { readonly same: boolean; readonly by: Decider };The verdict of a comparison: whether the files are the same, and what decided.
isContentHashconstno test imports itconst isContentHash: (rev: Revision) => booleanWhether the revision of a file is the SHA-256 of its bytes.
digestOffunctionfunction digestOf(side: Side, cache?: DigestCache | undefined): Promise<Result<string, Problem>>The SHA-256 of a file in hex: from its revision where that is the hash, from the cache, or from its bytes.
comparefunctionfunction compare(src: Side, dst: Side, comparators: readonly ("content-hash" | "native-digest" | "size-mtime")[], cache?: DigestCache | undefined): Promise<Result<Verdict, Problem>>Compares two files by the comparators in order; the first that can decide decides. Where none can, the files are taken to differ, so that they are copied again.
digestOfPathfunctionno test imports itfunction digestOfPath(store: Store<"read">, path: Path): Promise<Result<string, Problem>>The digest of a path read for its own sake: used where a plan needs the bytes' hash and no stat.