[][src]Struct qbsdiff::bspatch::Bspatch

pub struct Bspatch<'p> { /* fields omitted */ }

Fast and memory saving patcher comaptible with bspatch.

Apply patch with a 4k copy buffer and a 1k-4k delta cache buffer:

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

fn bspatch(source: &[u8], patch: &[u8]) -> io::Result<Vec<u8>> {
    let mut target = Vec::new();
    Bspatch::new(patch)?
        .buffer_size(4096)
        .delta_min(1024)
        .apply(source, io::Cursor::new(&mut target))?;
    Ok(target)
}

Preallocate target file before applying patch:

use std::io;
use std::fs::File;
use std::path::Path;
use qbsdiff::Bspatch;

fn file_allocate(file: &mut File, size: u64) -> io::Result<()> {
    unimplemented!()
}

fn bspatch<P: AsRef<Path>>(source: &[u8], target: P, patch: &[u8]) -> io::Result<u64> {
    let patcher = Bspatch::new(patch)?;
    let mut target_file = File::create(target)?;
    file_allocate(&mut target_file, patcher.hint_target_size())?;
    patcher.apply(source, &mut target_file)
}

Methods

impl<'p> Bspatch<'p>[src]

pub fn new(patch: &'p [u8]) -> Result<Self>[src]

Parse the patch file and create new patcher configuration.

Return error if failed to parse the patch header.

pub fn buffer_size(self, bs: usize) -> Self[src]

Set the main copy buffer size, (bs > 128, default is BUFFER_SIZE).

This is also the write buffer to target stream. A relative big buffer (usually 128k) will speed up writing process if the target stream is unbuffered (e.g. std::fs::File).

pub fn delta_min(self, dm: usize) -> Self[src]

Sets the initial delta cache size, (dm > 128, default is DELTA_MIN).

The delta cache is dynamic and can grow up when needed (but keeps not greater than the size of main copy buffer).

This might be deprecated in later version.

pub fn hint_target_size(&self) -> u64[src]

Hint the final target file size.

pub fn apply<T: Write>(self, source: &[u8], target: T) -> Result<u64>[src]

Apply patch to the source data and output the stream of target.

The target data size would be returned if no error occurs.

Auto Trait Implementations

impl<'p> RefUnwindSafe for Bspatch<'p>

impl<'p> Send for Bspatch<'p>

impl<'p> Sync for Bspatch<'p>

impl<'p> Unpin for Bspatch<'p>

impl<'p> UnwindSafe for Bspatch<'p>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.