[][src]Function xdelta3::encode

pub fn encode(input: &[u8], src: &[u8]) -> Option<Vec<u8>>

Function to generate the difference data

This function is used to generate the difference data. The data in src will be treated as "original" data and the data in input will be treated as "after", "patched" or "expected" data.

If you want to build an application that applies patches or differential updates, this function is used to generate the patch data (or update files). When generating the patch file, you might want to read your old file into a &[u8] and pass that variable to the src parameter and read your new file into another &[u8] and pass that variable to the input parameter. And then you could write the output of this function to a file.

Here is a basic example to show how to use this function:

extern crate xdelta3;
use xdelta3::encode;

fn main() {
    let result = encode(&[1, 2, 3, 4, 5, 6, 7], &[1, 2, 4, 4, 7, 6, 7]);
    assert_eq!(result.unwrap().as_slice(), &[214, 195, 196, 0, 0, 0, 13, 7, 0, 7, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8]);
}

You might notice the generated patch data is larger than both orginal data and the updated data. But don't worry, if your data is large enough and kind of similar between each other (usually the case for software updates or ROM patches), the patch data should be only a fraction of your updated file.