Scanner

Struct Scanner 

Source
pub struct Scanner { /* private fields */ }
Expand description

An engine that hashes data, looking for good split points. When it finds a split point, it emits the length of the block and its hash (SHA-256, Blake2, or Blake3).

You can configure the window size, preferred block size, and min/max block sizes (all in powers of 2).

Implementations§

Source§

impl Scanner

Source

pub fn new( hash_type: HashType, min_bits: u8, pref_bits: u8, max_bits: u8, window_bits: u8, ) -> Scanner

Create a new scanner with:

  • hash_type: which hashing function to use
  • min_bits: minimum block size
  • pref_bits: preferred block size
  • max_bits: maximum block size
  • window_bits: size of the rolling buffer, or how far back to include in the rolling hash

All sizes are in powers of 2, so Scanner::new(18, 20, 22, 10) will use a window size of 1K, a preferred block size of 1M, and a min/max of 256K/4M.

Source

pub fn feed(&mut self, data: &[u8]) -> (usize, Option<Block>)

Process a chunk of data and determine if we’ve hit a block boundary. Returns the number of bytes consumed, and optionally block metadata. If it returns a block, it may not have finished processing this chunk of data, so if consumed < data.len(), then you should call this method again, with &data[consumed..].

Source

pub fn finish(&mut self) -> Option<Block>

Terminate the scanner. Return a block if there was one in flight. It may be smaller than the minimum size.

Source

pub fn reader_iter<'a, R: Read>( &'a mut self, reader: &'a mut R, buffer: &'a mut [u8], digest: &'a mut Hashing, ) -> ScanIterator<'a, R>

Scan a reader (Read), using a given temporary buffer, and computing a SHA-256 hash as we go.

Source

pub fn scan_reader( &mut self, reader: &mut impl Read, buffer: &mut [u8], hash_type: HashType, ) -> Result<FileBlocks>

Exhaustively scan a Read and return a vector of blocks. The scanner is reset at the end so that it can be immediately reused on another reader.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.