Byte-level file/text comparison and verification library built on adamlibrary's C extension modules
Project description
bytecheck
A small library for byte-level comparison and verification between two files or byte sequences, built on top of adamlibrary's C extension modules.
This is meant to be used as a library first. Importing bytecheck
doesn't parse argv or touch stdin - the CLI is just a thin optional
layer on top.
Install
pip install -e .
Library usage
import bytecheck
data_a = open("file1.bin", "rb").read()
data_b = open("file2.bin", "rb").read()
result = bytecheck.verify(data_a, data_b)
print(result["match_ratio"]) # e.g. 85.71
print(result["identical"]) # True/False
print(result["mismatched_offsets"]) # list of byte offsets that differ
# Convenience wrappers
bytecheck.is_identical(data_a, data_b)
bytecheck.match_ratio(data_a, data_b)
verify() returns a plain dict:
| Key | Meaning |
|---|---|
size_a / size_b |
length of each input in bytes |
chunk_size |
comparison chunk size used |
total_chunks |
number of chunks compared |
matching_chunks / mismatched_chunks |
counts |
match_ratio |
percentage of matching chunks |
mismatched_offsets |
byte offsets where chunks differed |
identical |
True if both inputs match exactly |
Optional CLI
Installing this package also registers a bytecheck console script,
and the package can be run directly as a module:
bytecheck file1.bin file2.bin
python -m bytecheck file1.bin file2.bin --chunk-size 16
python -m bytecheck --text "hello world" --text2 "hello worle"
python -m bytecheck file1.bin file2.bin --quiet # just IDENTICAL/DIFFERENT + exit code
CLI flags:
| Flag | Description |
|---|---|
file_a, file_b |
files to compare |
--text, --text2 |
compare text directly instead of files |
--chunk-size N |
comparison chunk size in bytes (default: 8) |
--quiet |
only print IDENTICAL/DIFFERENT, exit code 0/1 |
C backend usage
| Module | adamlibrary function used | Purpose |
|---|---|---|
bytecheck.core |
adam.memcpy |
copies each input through the C extension before comparison |
bytecheck.core |
datasetname.memcmp |
byte-for-byte chunk comparison |
Note: the binding of datasetname.memcmp takes its arguments as C
strings, which cannot contain an embedded null byte. Real binary data
can contain 0x00, so each null byte is remapped to 0x01 on both
sides before comparing chunks. This is a simple workaround, not a
perfect one - null support may be added to adamlibrary itself in the
future, since this is one of the modules in the adamlibrary
infrastructure. A genuine 0x00 vs 0x01 difference at the same
offset can be masked by the remap, but that's an acceptable trade-off
for a spot check of similarity between two byte streams.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bytecheck-1.0.0-py3-none-any.whl.
File metadata
- Download URL: bytecheck-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b6754e91bdedc946ff266729b303276d425aba291ab846373b3833adabf6951
|
|
| MD5 |
c377874b890e47c01d037829a93ac0fa
|
|
| BLAKE2b-256 |
96fe73a3478c5c4b2ebdba14f5c9aa119a7674d7b1b03746d549db3f410720c8
|