Skip to main content

BlockReader

Struct BlockReader 

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

A builder for a fixed block size file reader.

Implementations§

Source§

impl BlockReader

Source

pub fn new<P>(fname: P, block_size: usize) -> Self
where P: AsRef<Path>,

Construct a new BlockReader builder.

Defaults to a queue limit of 2 blocks.

§Panics

The block_size must be greater than zero.

Source

pub fn queue_size(self, len: usize) -> Self

Set the queue size, in number of blocks.

This configures how many blocks can be “in-flight”.

§Panics

The len parameter mus be greater than zero.

Source§

impl BlockReader

Source

pub fn proc<F, E>(self, f: F) -> Result<(), E>
where F: FnMut(&[u8]) -> ControlFlow<E>, E: From<Error>,

Read file block-by-block and call a closure to process each block.

There’s an assumption that the file’s size will not change: Once the end of the file has been reached, the function will return.

§Internals

This function does not carry any blocks in-flight apart from the block currently being processed. It is intended to be used when the closure returns quickly.

§Errors
Source

pub fn proc_thrd<F, E>(self, f: F) -> Result<(), E>
where F: FnMut(Vec<u8>) -> ControlFlow<E>, E: From<Error> + Send + 'static,

Read file block-by-block on a background thread and pass each block via a channel to a closure.

This method should be preferred over BlockReader::proc() if the closure needs ownership of the blocks and its processing is non-trivial (i.e. the background thread can pre-load the next block).

§Errors

Returns a caller-defined error E which must be convertible from a std::io::Error. If the

Source

pub fn channel( self, ) -> Result<(Receiver<Result<Vec<u8>, Error>>, JoinHandle<()>), Error>

Open a file and return a channel receiver end-point that will return the file’s contents block-by-block.

Once the file’s end-of-file has been reached, the transmitting end-point will be dropped, which will cause the receiver end-point to fail once the remaining blocks have been read.

§Errors
Source

pub fn try_iter(self) -> Result<BlockIter, Error>

Return an Iterator which yields the file’s blocks.

§Errors

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> Chain<T> for T

Source§

fn len(&self) -> usize

The number of items that this chain link consists of.
Source§

fn append_to(self, v: &mut Vec<T>)

Append the elements in this link to the chain.
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> PipeIf for T

Source§

fn pipe_if<F>(self, predicate: bool, f: F) -> Self
where F: FnOnce(Self) -> Self,

Pipe a value through a closure if predicate is true.
Source§

fn pipe_opt<T, F>(self, opt: Option<T>, f: F) -> Self
where F: FnOnce(Self, T) -> Self,

Optionally pipe a value through a closure.
Source§

fn pipe_optref<T, F>(self, opt: Option<&T>, f: F) -> Self
where F: FnOnce(Self, &T) -> Self,

Optionally pipe a reference to a value through a closure.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V