Crate files_diff

Source
Expand description

A library for generating and applying binary diffs between files and archives.

This library provides efficient differing algorithms to generate patches between binary files or zip archives. It supports multiple differing algorithms (rsync and bidiff) and compression methods to optimize patch sizes.

§Basic Usage

use files_diff::{diff, apply, DEFAULT_ALGO};

let before = b"hello world";
let after = b"hello darkness my old friend";

// Generate a patch using default algorithms
let (diff_algo, compress_algo) = DEFAULT_ALGO;
let patch = diff(before, after, diff_algo, compress_algo)?;

// Apply the patch to recreate the target file
let result = apply(before, &patch)?;
assert_eq!(&result, after);

§Advanced Usage

use files_diff::{diff_zip, apply_zip, DiffAlgorithm, CompressAlgorithm};

// For zip archives, use the specialized zip functions
let patch_set = diff_zip(
    "before.zip".to_string(),
    "after.zip".to_string(),
    DiffAlgorithm::Bidiff1,
    CompressAlgorithm::Zstd
)?;

// Apply patches to transform the original zip
apply_zip("before.zip", patch_set, "result.zip".to_string())?;

The library uses fast-rsync for the rsync algorithm and bidiff for the bidiff algorithm. Each patch includes hash validation to ensure data integrity during the patching process.

Structs§

Patch
A patch that can transform one file into another.
PatchSet
A collection of file operations that transform one archive into another.

Enums§

CompressAlgorithm
Compression algorithms available for patch data.
DiffAlgorithm
Algorithms available for generating binary diffs.
Error
Errors that can occur during differing and patching operations.

Constants§

DEFAULT_ALGO
The default diff and compression algorithm.

Traits§

DiffMachine
A trait that implements differing and patching operations.

Functions§

apply
Applies a patch to transform the base data.
apply_zip
Applies a patch set to transform a zip archive into a new version.
diff
Generates a patch between two byte slices using specified algorithms.
diff_zip
Generates a patch set that can transform one zip archive into another.
hash
Generates an MD5 hash of the provided data as a hexadecimal string.