6 releases
| 0.1.5 | Jan 14, 2026 |
|---|---|
| 0.1.4 | Jan 5, 2026 |
| 0.1.3 | Dec 16, 2025 |
| 0.1.2 | Jun 26, 2025 |
#349 in Compression
22KB
541 lines
bitcut
bitcut is a simple CLI tool for creating and applying binary patches.
Motivation
When two binary files are similar, rewriting or transmitting the entire new version can be inefficient. This tool reduces the cost by generating a compact binary patch that represents only the difference. The new file can then be reconstructed by applying the patch to the original.
Patch Format
A patch is a sequence of opcodes:
Copy (0x00, offset, len): Copy len bytes from offset in the original file.Add (0x01, len, bytes): Add len new bytes directly.
Patch Generation
The original file is indexed using a sliding window (default: 8 bytes).
The new file is scanned with the same window.
If a match is found in the original file, the longest matching sequence is emitted as a Copy.
Otherwise, unmatched bytes are grouped into an Add.
Patch Application
To apply a patch:
- Start with an empty output buffer.
- Iterate over the patch:
- Copy: append bytes from the original file.
- Add: append new bytes from the patch.
This reconstructs the new version of the file.
When to Use
This tool works best when the two binary files are mostly similar — for example, when only small regions have changed.
Commands
diff
Creates a binary patch from two files and writes the patch to stdout.
bitcut diff old_file.bin new_file.bin > patch.bin
patch
Applies a binary patch to a file and writes the result to stdout.
bitcut patch old_file.bin patch.bin > new_file.bin
Install from sources
cargo install bitcut
Build
cargo build --release
Run
./target/release/bitcut diff a.bin b.bin > patch
./target/release/bitcut patch a.bin patch > b.bin
Dependencies
~23–280KB