FileContents

Trait FileContents 

Source
pub trait FileContents: Send + Sync {
    // Required methods
    fn len(&self) -> u64;
    fn read_bytes_at(
        &self,
        offset: u64,
        size: u64,
    ) -> FileAndPathHelperResult<&[u8]>;
    fn read_bytes_at_until(
        &self,
        range: Range<u64>,
        delimiter: u8,
    ) -> FileAndPathHelperResult<&[u8]>;
    fn read_bytes_into(
        &self,
        buffer: &mut Vec<u8>,
        offset: u64,
        size: usize,
    ) -> FileAndPathHelperResult<()>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Provides synchronous access to the raw bytes of a file. This trait needs to be implemented by the consumer of this crate.

Required Methods§

Source

fn len(&self) -> u64

Must return the length, in bytes, of this file.

Source

fn read_bytes_at( &self, offset: u64, size: u64, ) -> FileAndPathHelperResult<&[u8]>

Must return a slice of the file contents, or an error. The slice’s lifetime must be valid for the entire lifetime of this FileContents object. This restriction may be a bit cumbersome to satisfy; it’s a restriction that’s inherited from the object crate’s ReadRef trait.

Source

fn read_bytes_at_until( &self, range: Range<u64>, delimiter: u8, ) -> FileAndPathHelperResult<&[u8]>

TODO: document

Source

fn read_bytes_into( &self, buffer: &mut Vec<u8>, offset: u64, size: usize, ) -> FileAndPathHelperResult<()>

Append size bytes to buffer, starting to read at offset in the file. If successful, buffer must have had its len increased exactly by size, otherwise the caller may panic.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the file is empty.

Implementors§

Source§

impl<S: FileByteSource> FileContents for FileContentsWithChunkedCaching<S>

Source§

impl<T: Deref<Target = [u8]> + Send + Sync> FileContents for T

Implementation for slices.