thediff 0.1.0

Difference between 2 files in percentages
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 4.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.11 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Atshemyan

thediff

A small Rust crate for calculating how different two files are, expressed as a percentage.
It is useful for file comparison, integrity checks, similarity analysis, or detecting changes between binary or text files.


Installation

Add the crate to your Cargo.toml:

[dependencies]
thediff = "0.1"

Usage

Compare Two Files

use std::path::Path;

use thediff::thediff;

fn main() -> std::io::Result<()> {
    let (diff_percent, same_percent) = thediff(Path::new("file1.bin"), Path::new("file2.bin"))?;
    println!(
        "Different part: {:.2}%, Same part: {:.2}%",
        diff_percent, same_percent
    );
    Ok(())
}

use std::path::Path;
use thediff::thediff_async;

#[tokio::main]
async fn main() -> std::io::Result<()> {
    let (diff_percent, same_percent) =
        thediff_async(
            Path::new("file1.bin"),
            Path::new("file2.bin"),
        )
        .await?;

    println!(
        "Different part: {:.2}%, Same part: {:.2}%",
        diff_percent, same_percent
    );

    Ok(())
}


How It Works

The crate compares files utf8 char by char:

  • Counts how many chars differ
  • Handles files of different sizes
  • Extra bytes in the longer file are treated as differences

Examples

File A File B Result
Identical Identical 0%
50% bytes differ Same length 50%
One file empty Other non-empty 100%