Struct rust_unixfs::file::adder::FileAdder
source · pub struct FileAdder { /* private fields */ }
Expand description
File tree builder. Implements core::default::Default
which tracks the recent defaults.
Custom file tree builder can be created with FileAdder::builder()
and configuring the
chunker and collector.
Current implementation maintains an internal buffer for the block creation and uses a non-customizable hash function to produce Cid version 0 links. Currently does not support inline links.
Implementations§
source§impl FileAdder
impl FileAdder
sourcepub fn builder() -> FileAdderBuilder
pub fn builder() -> FileAdderBuilder
Returns a FileAdderBuilder
for creating a non-default FileAdder.
sourcepub fn size_hint(&self) -> usize
pub fn size_hint(&self) -> usize
Returns the likely amount of buffering the file adding will work with best.
When using the size based chunker and input larger than or equal to the hint is push()
’ed
to the chunker, the internal buffer will not be used.
sourcepub fn push(
&mut self,
input: &[u8]
) -> (impl Iterator<Item = (Cid, Vec<u8>)>, usize)
pub fn push( &mut self, input: &[u8] ) -> (impl Iterator<Item = (Cid, Vec<u8>)>, usize)
Called to push new file bytes into the tree builder.
Returns the newly created blocks (at most 2) and their respective Cids, and the amount of
input
consumed.
sourcepub fn finish(self) -> impl Iterator<Item = (Cid, Vec<u8>)>
pub fn finish(self) -> impl Iterator<Item = (Cid, Vec<u8>)>
Called after the last FileAdder::push
to finish the tree construction.
Returns a list of Cids and their respective blocks.
Note: the API will hopefully evolve in a direction which will not allocate a new Vec for every block in the near-ish future.