pub struct FileChunker { /* private fields */ }Expand description
Streaming content-addressed chunker.
Construct one via FileChunker::new, push bytes with
FileChunker::write, and call FileChunker::finalize to get
the root address. Optionally pass an on_chunk callback to
FileChunker::with_callback to be notified as each chunk is
sealed (useful for streaming uploads).
Implementations§
Source§impl FileChunker
impl FileChunker
Sourcepub fn with_callback<F>(callback: F) -> Self
pub fn with_callback<F>(callback: F) -> Self
New chunker with an on-chunk callback. The callback runs synchronously as each leaf or intermediate chunk is sealed.
Sourcepub fn write(&mut self, data: &[u8]) -> Result<usize, Error>
pub fn write(&mut self, data: &[u8]) -> Result<usize, Error>
Append bytes to the input stream. As each leaf reaches
CHUNK_SIZE it is sealed and propagated up the level stack.
Sourcepub fn finalize(self) -> Result<ChunkerRoot, Error>
pub fn finalize(self) -> Result<ChunkerRoot, Error>
Seal any trailing partial leaf, collapse the level stack, and return the root chunk’s address + span. An empty chunker (zero bytes written) is rejected as it has no valid root.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileChunker
impl !RefUnwindSafe for FileChunker
impl Send for FileChunker
impl !Sync for FileChunker
impl Unpin for FileChunker
impl UnsafeUnpin for FileChunker
impl !UnwindSafe for FileChunker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more