pub struct StreamingChunker { /* private fields */ }Expand description
Stateful streaming chunker – feeds data incrementally, emits chunks as boundaries are found.
Unlike chunk_slice() which needs the full data in memory, StreamingChunker
processes data in arbitrary-sized reads and emits Chunk objects as gear-hash
boundaries are detected.
§Example
let mut sc = StreamingChunker::new(&GearChunker::new(2048, 65536, 2097152).unwrap());
let mut file = std::fs::File::open("large_file.dat").unwrap();
let mut buf = [0u8; 1_048_576]; // 1MB read buffer
use std::io::Read;
loop {
let n = file.read(&mut buf).unwrap();
if n == 0 { break; }
for chunk in sc.feed(&buf[..n]) {
// Process each chunk (upload, hash, etc.)
}
}
let (final_chunk, _file_hash) = sc.finish();Implementations§
Source§impl StreamingChunker
impl StreamingChunker
Sourcepub fn new(chunker: &GearChunker) -> Self
pub fn new(chunker: &GearChunker) -> Self
Create a new streaming chunker from a GearChunker configuration.
Sourcepub fn feed(&mut self, data: &[u8]) -> Vec<Chunk>
pub fn feed(&mut self, data: &[u8]) -> Vec<Chunk>
Feed data into the chunker and return any completed chunks.
Auto Trait Implementations§
impl Freeze for StreamingChunker
impl RefUnwindSafe for StreamingChunker
impl Send for StreamingChunker
impl Sync for StreamingChunker
impl Unpin for StreamingChunker
impl UnsafeUnpin for StreamingChunker
impl UnwindSafe for StreamingChunker
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more