Initial project outline
- package.json (ESM, bin entry) - bin/delta-backup.js — entrypoint - lib/args.js — CLI arg parsing via Node parseArgs - lib/config.js — config file merging + required path guards - lib/spawn.js — safe process spawning (no shell strings) - lib/state.js — sequence number + phase state management - lib/backends/zstd.js — zstd delta backend - lib/backends/index.js — backend registry - lib/commands/run.js — full run skeleton (phases 1-3 wired, 4-6 stubbed) - lib/commands/status.js — status command
This commit is contained in:
35
lib/backends/zstd.js
Normal file
35
lib/backends/zstd.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* zstd delta backend.
|
||||
*
|
||||
* Modified files: zstd --patch-from=prev new -o out.zst
|
||||
* New files: zstd new -o out.zst (no base, just compress)
|
||||
* Deleted files: no delta file, manifest entry only
|
||||
*/
|
||||
import { run } from '../spawn.js';
|
||||
|
||||
export const name = 'zstd';
|
||||
export const ext = '.zst';
|
||||
|
||||
/**
|
||||
* Create a delta from prevFile to newFile, output to outFile.
|
||||
* If prevFile is null, newFile is new — compress without a base.
|
||||
*/
|
||||
export async function createDelta(prevFile, newFile, outFile, { dryRun } = {}) {
|
||||
if (prevFile) {
|
||||
await run('zstd', ['--patch-from', prevFile, newFile, '-o', outFile, '-f'], { dryRun });
|
||||
} else {
|
||||
await run('zstd', [newFile, '-o', outFile, '-f'], { dryRun });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a delta on top of prevFile to produce outFile.
|
||||
* If prevFile is null, the delta is a plain compressed file.
|
||||
*/
|
||||
export async function applyDelta(prevFile, deltaFile, outFile, { dryRun } = {}) {
|
||||
if (prevFile) {
|
||||
await run('zstd', ['-d', '--patch-from', prevFile, deltaFile, '-o', outFile, '-f'], { dryRun });
|
||||
} else {
|
||||
await run('zstd', ['-d', deltaFile, '-o', outFile, '-f'], { dryRun });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user