#delta-compression #delta #bsdiff #suffix-array #compatible #memory #patch

bin+lib qbsdiff

Fast and memory saving bsdiff 4.x compatible delta compressor and patcher

14 releases (stable)

1.4.2 Apr 15, 2024
1.4.1 Jun 22, 2023
1.4.0 Sep 17, 2021
1.3.1 Apr 25, 2020
0.1.2 Oct 17, 2019

#59 in Compression

Download history 85/week @ 2024-07-22 44/week @ 2024-07-29 71/week @ 2024-08-05 76/week @ 2024-08-12 87/week @ 2024-08-19 119/week @ 2024-08-26 48/week @ 2024-09-02 32/week @ 2024-09-09 59/week @ 2024-09-16 113/week @ 2024-09-23 65/week @ 2024-09-30 40/week @ 2024-10-07 38/week @ 2024-10-14 151/week @ 2024-10-21 111/week @ 2024-10-28 86/week @ 2024-11-04

390 downloads per month
Used in 5 crates (4 directly)

MIT license

42KB
799 lines

qbsdiff

crates docs dependency status

Fast and memory saving bsdiff 4.x compatible delta compressor and patcher.

Add dependency to Cargo.toml:

[dependencies]
qbsdiff = "1.4"

Build commands

Build qbsdiff and qbspatch commands:

$ cargo build --release --bins --features cmd
$ cd target/release
$ ./qbsdiff --help
$ ./qbspatch --help

Install commands to $CARGO_HOME/bin:

$ cargo install qbsdiff --features cmd

Examples

Produce the target stream by applying patch to source:

use std::io;
use qbsdiff::Bspatch;

fn bspatch(source: &[u8], patch: &[u8]) -> io::Result<Vec<u8>> {
    let patcher = Bspatch::new(patch)?;
    let mut target = Vec::new();
    // To preallocate target:
    //Vec::with_capacity(patcher.hint_target_size() as usize);
    patcher.apply(source, io::Cursor::new(&mut target))?;
    Ok(target)
}

Produce the patch data by comparing source with target:

use std::io;
use qbsdiff::Bsdiff;

fn bsdiff(source: &[u8], target: &[u8]) -> io::Result<Vec<u8>> {
    let mut patch = Vec::new();
    Bsdiff::new(source, target)
        .compare(io::Cursor::new(&mut patch))?;
    Ok(patch)
}

Note that qbsdiff would not generate exactly the same patch file as bsdiff. Only the patch file format is promised to be compatible.

Dependencies

~2–3MB
~52K SLoC