Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bytecheck-1.0.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

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

Hashes for bytecheck-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b6754e91bdedc946ff266729b303276d425aba291ab846373b3833adabf6951
MD5 c377874b890e47c01d037829a93ac0fa
BLAKE2b-256 96fe73a3478c5c4b2ebdba14f5c9aa119a7674d7b1b03746d549db3f410720c8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page