6 releases

0.2.1 Mar 31, 2025
0.2.0 Apr 11, 2024
0.1.6 Aug 8, 2021
0.1.5 Jul 31, 2021
0.1.3 Jun 24, 2017

#66 in Compression

Download history 2593/week @ 2026-01-19 3487/week @ 2026-01-26 1809/week @ 2026-02-02 3647/week @ 2026-02-09 1666/week @ 2026-02-16 2113/week @ 2026-02-23 3635/week @ 2026-03-02 4430/week @ 2026-03-09 4148/week @ 2026-03-16 1903/week @ 2026-03-23 2897/week @ 2026-03-30 5025/week @ 2026-04-06 7240/week @ 2026-04-13 6223/week @ 2026-04-20 15469/week @ 2026-04-27 14251/week @ 2026-05-04

43,598 downloads per month
Used in 12 crates (8 directly)

BSD-2-Clause

20KB
390 lines

bsdiff-rs

GitHub crates.io version docs.rs docs crates.io version CI build

Bsdiff is a method of diffing files. This crate is a port of a bsdiff library. High performance patching. All written in safe Rust.

It is usually a good idea to use bsdiff alongside a compression algorithm like bzip2.

Usage

fn main() {
    let one = vec![1, 2, 3, 4, 5];
    let two = vec![1, 2, 4, 6];
    let mut patch = Vec::new();

    bsdiff::diff(&one, &two, &mut patch).unwrap();

    let mut patched = Vec::with_capacity(two.len());
    bsdiff::patch(&one, &mut patch.as_slice(), &mut patched).unwrap();
    assert_eq!(patched, two);
}

Diffing Files

fn diff_files(file_a: &str, file_b: &str, patch_file: &str) -> std::io::Result<()> {
    let old = std::fs::read(file_a)?;
    let new = std::fs::read(file_b)?;
    let mut patch = Vec::new();

    bsdiff::diff(&old, &new, &mut patch)?;
    // TODO: compress `patch` here
    std::fs::write(patch_file, &patch)
}

Patching Files

fn patch_file(file_a: &str, patch_file: &str, file_b: &str) -> std::io::Result<()> {
    let old = std::fs::read(file_a)?;
    let patch = std::fs::read(patch_file)?;
    // TODO: decompress `patch` here
    let mut new = Vec::new();

    bsdiff::patch(&old, &mut patch.as_slice(), &mut new)?;
    std::fs::write(file_b, &new)
}

No runtime deps