qbsdiff/
lib.rs

1/*!
2Fast and memory saving bsdiff 4.x compatible delta compressor and patcher.
3
4Add dependency to `Cargo.toml`:
5```toml
6[dependencies]
7qbsdiff = "1.4"
8```
9
10Build commands
11--------------
12
13Build `qbsdiff` and `qbspatch` commands:
14```shell
15$ cargo build --release --bins --features cmd
16$ cd target/release
17$ ./qbsdiff --help
18$ ./qbspatch --help
19```
20Install commands to `$CARGO_HOME/bin`:
21```shell
22$ cargo install qbsdiff --features cmd
23```
24
25Examples
26--------
27
28Produce the target stream by applying `patch` to `source`:
29```rust
30use std::io;
31use qbsdiff::Bspatch;
32
33fn bspatch(source: &[u8], patch: &[u8]) -> io::Result<Vec<u8>> {
34    let patcher = Bspatch::new(patch)?;
35    let mut target = Vec::new();
36    // To preallocate target:
37    //Vec::with_capacity(patcher.hint_target_size() as usize);
38    patcher.apply(source, io::Cursor::new(&mut target))?;
39    Ok(target)
40}
41```
42
43Produce the patch data by comparing `source` with `target`:
44```rust
45use std::io;
46use qbsdiff::Bsdiff;
47
48fn bsdiff(source: &[u8], target: &[u8]) -> io::Result<Vec<u8>> {
49    let mut patch = Vec::new();
50    Bsdiff::new(source, target)
51        .compare(io::Cursor::new(&mut patch))?;
52    Ok(patch)
53}
54```
55
56Note that `qbsdiff` would not generate exactly the same patch file as `bsdiff`.
57Only the patch file format is promised to be compatible.
58 */
59
60#![forbid(unsafe_code)]
61
62pub use bsdiff::{Bsdiff, ParallelScheme};
63pub use bspatch::Bspatch;
64
65pub mod bsdiff;
66pub mod bspatch;
67mod utils;