AsChunks

Trait AsChunks 

Source
pub trait AsChunks<'a>: Sized + Sealed {
    // Required method
    fn as_chunks(&self) -> ChunkIter<'a> ;

    // Provided methods
    fn as_reader<'b, R: ?Sized>(
        &self,
        archive: &'b mut Archive<R>,
    ) -> ChunksReader<'a, 'b, R>  { ... }
    fn read_to_vec<R: ReadAt + ?Sized>(
        &self,
        archive: &mut Archive<R>,
    ) -> Result<Vec<u8>> { ... }
}
Expand description

Trait for data-bearing objects, notably Files and Chunks.

In DwarFS, regular files consist of multiple chunks of data concatenated for deduplication. You can iterate over these chunks and locate section index and offsets in order to retrieve the actual bytes.

This trait provides some convenient methods to access all these bytes as a Read instance via AsChunks::as_reader so you can easily std::io::copy it as a whole to the destination.

AsChunks::read_to_vec can also be used to efficiently read all data into memory.

Required Methods§

Source

fn as_chunks(&self) -> ChunkIter<'a>

Iterate over all chunks this object consists of.

Provided Methods§

Source

fn as_reader<'b, R: ?Sized>( &self, archive: &'b mut Archive<R>, ) -> ChunksReader<'a, 'b, R>

Get a Read instance representing the concatenation of all chunks this object consists of.

The user must guarantee the owning ArchiveIndex of self and archive must come from the same DwarFS archive, or the behavior is unspecified: it may return garbage data, panic, or fail.

Source

fn read_to_vec<R: ReadAt + ?Sized>( &self, archive: &mut Archive<R>, ) -> Result<Vec<u8>>

Read all data from this object into a Vec.

This is a convenient shortcut method wrapping AsChunks::as_reader and Read::read_to_end.

See AsChunks::as_reader for the validity requirement on archive.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a> AsChunks<'a> for Chunk<'a>

Source§

impl<'a> AsChunks<'a> for ChunkIter<'a>

Source§

impl<'a> AsChunks<'a> for File<'a>