5个版本

0.2.0 2024年4月11日
0.1.6 2021年8月8日
0.1.5 2021年7月31日
0.1.3 2017年6月24日

#52压缩 分类中

Download history 232/week @ 2024-04-24 166/week @ 2024-05-01 252/week @ 2024-05-08 154/week @ 2024-05-15 222/week @ 2024-05-22 392/week @ 2024-05-29 271/week @ 2024-06-05 222/week @ 2024-06-12 255/week @ 2024-06-19 296/week @ 2024-06-26 334/week @ 2024-07-03 323/week @ 2024-07-10 335/week @ 2024-07-17 398/week @ 2024-07-24 481/week @ 2024-07-31 464/week @ 2024-08-07

1,722 每月下载量
4 crate中使用(直接使用2个)

BSD-2-Clause

20KB
399

bsdiff-rs

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

Bsdiff是一种文件差异比较的方法。这个crate是将bsdiff库移植到Rust。高性能的补丁。全部使用安全的Rust编写。

通常,与bzip2之类的压缩算法一起使用bsdiff是个不错的选择。

使用方法

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);
}

文件比较

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)
}

文件修补

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)
}

无运行时依赖