@linxuekai/bsdiff-cli
v1.0.2
Published
Binary diff/patch CLI powered by bsdiff-wasm (WebAssembly)
Maintainers
Readme
@linxuekai/bsdiff-cli
Binary diff/patch CLI powered by bsdiff-wasm (WebAssembly).
Generates compact binary deltas between two files and applies them to reconstruct the new file — ideal for incremental updates, OTA patches, and version-to-version binary diffs.
Requirements
- Node.js >= 18
Install
npm install -g @linxuekai/bsdiff-cliCLI Usage
bsdiff diff <old-file> <new-file> <patch-out> # Create a binary patch
bsdiff patch <old-file> <patch-file> <new-out> # Apply a binary patchOptions
| Flag | Description |
|------|-------------|
| -h, --help | Show help |
| -v, --version | Show version |
Examples
# Generate a patch from v1.bin → v2.bin
bsdiff diff v1.bin v2.bin update.patch
# Apply the patch to restore v2.bin
bsdiff patch v1.bin update.patch v2-restored.binOutput
diff:
diff: v1.bin → v2.bin ⇒ update.patch
old 1.2 MB
new 1.3 MB
patch 45.2 KB
ratio 3.4% of newpatch:
patch: v1.bin + update.patch ⇒ v2-restored.bin
old 1.2 MB
patch 45.2 KB
restored 1.3 MBProgrammatic API
import { diff, patch } from '@linxuekai/bsdiff-cli';diff(oldFile, newFile, patchOut)
Generate a binary patch file.
| Parameter | Type | Description |
|-----------|------|-------------|
| oldFile | string | Path to the original file |
| newFile | string | Path to the new file |
| patchOut | string | Path where the patch will be written |
Returns: Promise<{ oldSize: number, newSize: number, patchSize: number }>
patch(oldFile, patchFile, outFile)
Apply a binary patch to reconstruct the new file.
| Parameter | Type | Description |
|-----------|------|-------------|
| oldFile | string | Path to the original file |
| patchFile | string | Path to the patch file |
| outFile | string | Path where the restored file will be written |
Returns: Promise<{ oldSize: number, patchSize: number, outSize: number }>
API Example
import { diff, patch } from '@linxuekai/bsdiff-cli';
// Create a patch
const result = await diff('v1.bin', 'v2.bin', 'update.patch');
console.log(`Patch size: ${result.patchSize} bytes`);
// Apply the patch
const restored = await patch('v1.bin', 'update.patch', 'v2-restored.bin');
console.log(`Restored size: ${restored.outSize} bytes`);How It Works
The library wraps the classic bsdiff/bspatch algorithms compiled to WebAssembly via bsdiff-wasm. File paths are resolved to a common ancestor directory, which is mounted into the WASM module's NODEFS virtual filesystem. The underlying C main() is then invoked with relative paths.
License
MIT
