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

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

Fast and memory saving patcher comaptible with bspatch.

Apply patch to source using a 4k 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)
        .apply(source, io::Cursor::new(&mut target))?;
    Ok(target)
}

Preallocate target vector before applying patch:

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::with_capacity(patcher.hint_target_size() as usize);
    patcher.apply(source, io::Cursor::new(&mut target))?;
    Ok(target)
}

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

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, as provided in the patch header.

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.