{"file":"client/src/blobs.ts","version":318,"total":65,"from":1,"to":65,"lines":[{"n":1,"text":"// Binary files (#27): content-addressed blobs. The server keeps a binary","atom":"a0","author":"init","version":0},{"n":2,"text":"// file's bytes by their SHA-256 (PUT and GET /p/:project/blobs/<sha256>), and","atom":"a0","author":"init","version":0},{"n":3,"text":"// the file in the graph points at that hash. The client keeps the hash it","atom":"a0","author":"init","version":0},{"n":4,"text":"// knows for each binary file in .avcs/blobs.json, as it keeps the known copy","atom":"a0","author":"init","version":0},{"n":5,"text":"// of a text file, and uploads only a hash the server hasn't been told about.","atom":"a0","author":"init","version":0},{"n":6,"text":"","atom":"a0","author":"init","version":0},{"n":7,"text":"import { createHash } from \"node:crypto\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { readFileSync, statSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":9,"text":"import { join } from \"node:path\";","atom":"a0","author":"init","version":0},{"n":10,"text":"import { writeFileAtomic } from \"./folder.ts\";","atom":"a0","author":"init","version":0},{"n":11,"text":"import { stateDir } from \"./state-dir.ts\";","atom":"a94","author":"review","version":17},{"n":12,"text":"","atom":"a0","author":"init","version":0},{"n":13,"text":"/** The server's limit for one file's bytes. */","atom":"a0","author":"init","version":0},{"n":14,"text":"export const MAX_BLOB_BYTES = 20 * 1024 * 1024;","atom":"a0","author":"init","version":0},{"n":15,"text":"","atom":"a0","author":"init","version":0},{"n":16,"text":"const BLOBS_FILE = \"blobs.json\";","atom":"a0","author":"init","version":0},{"n":17,"text":"","atom":"a0","author":"init","version":0},{"n":18,"text":"export function sha256(bytes: Uint8Array): string {","atom":"a0","author":"init","version":0},{"n":19,"text":"\treturn createHash(\"sha256\").update(bytes).digest(\"hex\");","atom":"a0","author":"init","version":0},{"n":20,"text":"}","atom":"a0","author":"init","version":0},{"n":21,"text":"","atom":"a0","author":"init","version":0},{"n":22,"text":"/**","atom":"a0","author":"init","version":0},{"n":23,"text":" * Whether normalized text is the file the server keeps whole under `sha`","atom":"a0","author":"init","version":0},{"n":24,"text":" * (#46): a text file matching abso.json's \"whole\", or over 1 MB, is stored","atom":"a231","author":"review","version":28},{"n":25,"text":" * like a binary file, by the hash of its text with LF endings. The client","atom":"a0","author":"init","version":0},{"n":26,"text":" * keeps that hash in blobs.json, and the file on disk stays text.","atom":"a0","author":"init","version":0},{"n":27,"text":" */","atom":"a0","author":"init","version":0},{"n":28,"text":"export function keptWholeAs(text: string, sha: string | undefined): boolean {","atom":"a0","author":"init","version":0},{"n":29,"text":"\treturn sha !== undefined && sha256(Buffer.from(text, \"utf8\")) === sha;","atom":"a0","author":"init","version":0},{"n":30,"text":"}","atom":"a0","author":"init","version":0},{"n":31,"text":"","atom":"a0","author":"init","version":0},{"n":32,"text":"/** A file's bytes and their hash, or undefined when it is gone; `tooBig` when over the server's limit (bytes not read). */","atom":"a0","author":"init","version":0},{"n":33,"text":"export function blobOf(","atom":"a0","author":"init","version":0},{"n":34,"text":"\tpath: string,","atom":"a0","author":"init","version":0},{"n":35,"text":"): { sha: string; bytes: Uint8Array; size: number } | { tooBig: true; size: number } | undefined {","atom":"a0","author":"init","version":0},{"n":36,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":37,"text":"\t\tconst size = statSync(path).size;","atom":"a0","author":"init","version":0},{"n":38,"text":"\t\tif (size > MAX_BLOB_BYTES) return { tooBig: true, size };","atom":"a0","author":"init","version":0},{"n":39,"text":"\t\tconst bytes = readFileSync(path);","atom":"a0","author":"init","version":0},{"n":40,"text":"\t\treturn { sha: sha256(bytes), bytes, size };","atom":"a0","author":"init","version":0},{"n":41,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":43,"text":"\t}","atom":"a0","author":"init","version":0},{"n":44,"text":"}","atom":"a0","author":"init","version":0},{"n":45,"text":"","atom":"a0","author":"init","version":0},{"n":46,"text":"/** The binary files the server has, as far as the client knows: path -> sha256. */","atom":"a0","author":"init","version":0},{"n":47,"text":"export function readKnownBlobs(root: string): Map<string, string> {","atom":"a0","author":"init","version":0},{"n":48,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\treturn new Map(","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\t\tObject.entries(JSON.parse(readFileSync(join(stateDir(root), BLOBS_FILE), \"utf8\")) as Record<string, string>),","atom":"a94","author":"review","version":17},{"n":51,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":52,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\treturn new Map();","atom":"a0","author":"init","version":0},{"n":54,"text":"\t}","atom":"a0","author":"init","version":0},{"n":55,"text":"}","atom":"a0","author":"init","version":0},{"n":56,"text":"","atom":"a0","author":"init","version":0},{"n":57,"text":"export function writeKnownBlobs(root: string, blobs: ReadonlyMap<string, string>): void {","atom":"a0","author":"init","version":0},{"n":58,"text":"\tconst sorted = Object.fromEntries([...blobs].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));","atom":"a0","author":"init","version":0},{"n":59,"text":"\twriteFileAtomic(join(stateDir(root), BLOBS_FILE), `${JSON.stringify(sorted, null, 1)}\\n`);","atom":"a94","author":"review","version":17},{"n":60,"text":"}","atom":"a0","author":"init","version":0},{"n":61,"text":"","atom":"a0","author":"init","version":0},{"n":62,"text":"/** Short form of a hash for people: the first 12 hex digits. */","atom":"a0","author":"init","version":0},{"n":63,"text":"export function shortSha(sha: string | null | undefined): string {","atom":"a0","author":"init","version":0},{"n":64,"text":"\treturn sha ? sha.slice(0, 12) : \"(none)\";","atom":"a0","author":"init","version":0},{"n":65,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a94","author":"review","message":"","time":1791522261912,"timeIso":"2026-10-09T05:04:21.912Z","publish":{"draft":null,"version":17,"agent":"review","message":"New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.","time":1791522270512,"timeIso":"2026-10-09T05:04:30.512Z"}},{"atom":"a231","author":"review","message":"","time":1791539181105,"timeIso":"2026-10-09T09:46:21.105Z","publish":{"draft":null,"version":28,"agent":"review","message":"Client: abso.json is the project file (avcs.json still read; a new project gets abso.json unless it has either); new folders get .abso when no installed mod is older than 0.2.0; both mods are 0.2.0 (abso 253, 224)","time":1791539181568,"timeIso":"2026-10-09T09:46:21.568Z"}}]}