// Tests' twin of the stored-text compressor (lib/storedText-write-server.ts): // a fixture file put into its stored form the way the compressor leaves it — // `.zst` beside it with the plain file's times (numeric seconds), a // tier link's stored bytes beside its target in `media//` with a link of // the plain link's times — and the plain form removed (or kept, `keepPlain`). // Temp dirs only. import path from "node:path"; import { lstat, lutimes, readFile, readlink, rm, stat, symlink, utimes, writeFile } from "node:fs/promises"; import { encodeStoredBytes } from "../lib/storedText-server"; import { storedNameOf } from "../lib/storedText"; export async function storeFixture( videoDir: string, name: string, opts: { keepPlain?: boolean } = {}, ): Promise { const plain = path.join(videoDir, name); const l = await lstat(plain); if (l.isSymbolicLink()) { const rel = await readlink(plain); const target = path.resolve(videoDir, rel); const st = await stat(target); const storedBytes = path.join(path.dirname(target), storedNameOf(name)); await writeFile(storedBytes, await encodeStoredBytes(await readFile(target))); await utimes(storedBytes, st.atimeMs / 1000, st.mtimeMs / 1000); const link = path.join(videoDir, storedNameOf(name)); await symlink(path.join(path.dirname(rel), storedNameOf(name)), link); await lutimes(link, l.atimeMs / 1000, l.mtimeMs / 1000); if (!opts.keepPlain) { await rm(target); await rm(plain); } return; } const stored = path.join(videoDir, storedNameOf(name)); await writeFile(stored, await encodeStoredBytes(await readFile(plain))); await utimes(stored, l.atimeMs / 1000, l.mtimeMs / 1000); if (!opts.keepPlain) await rm(plain); }