IF Commons GitHub

logical/compare

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-bridge-transfer FR-002

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();

Source: commons/anyfs-bridge/src/logical/compare.ts

3 of 8 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

DigestCachetypeno test imports it
type 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.

memoryDigestCachefunction
function memoryDigestCache(): DigestCache

A cache in memory.

Imported by 15 tests of the run (15 passed, 0 failed): the library's results

Sidetypeno test imports it
type Side = { readonly store: Store<"read">; readonly stat: Stat };

One file with the store it is in: what a comparison needs.

Verdicttypeno test imports it
type Verdict = { readonly same: boolean; readonly by: Decider };

The verdict of a comparison: whether the files are the same, and what decided.

isContentHashconstno test imports it
const isContentHash: (rev: Revision) => boolean

Whether the revision of a file is the SHA-256 of its bytes.

digestOffunction
function 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.

Imported by 15 tests of the run (15 passed, 0 failed): the library's results

comparefunction
function 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.

Imported by 15 tests of the run (15 passed, 0 failed): the library's results

digestOfPathfunctionno test imports it
function 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.

Titles, headings, exports, tables, columns and requirements. Esc closes.