pub struct BlockReader { /* private fields */ }Expand description
A builder for a fixed block size file reader.
Implementations§
Source§impl BlockReader
impl BlockReader
Sourcepub fn new<P>(fname: P, block_size: usize) -> Self
pub fn new<P>(fname: P, block_size: usize) -> Self
Construct a new BlockReader builder.
Defaults to a queue limit of 2 blocks.
§Panics
The block_size must be greater than zero.
Sourcepub fn queue_size(self, len: usize) -> Self
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
impl BlockReader
Sourcepub fn proc<F, E>(self, f: F) -> Result<(), E>
pub fn proc<F, E>(self, f: F) -> Result<(), E>
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
Sourcepub fn proc_thrd<F, E>(self, f: F) -> Result<(), E>
pub fn proc_thrd<F, E>(self, f: F) -> Result<(), E>
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
Sourcepub fn channel(
self,
) -> Result<(Receiver<Result<Vec<u8>, Error>>, JoinHandle<()>), Error>
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.