pub struct ChunkedWriter { /* private fields */ }Expand description
A writer that processes data in chunks.
Implementations§
Source§impl ChunkedWriter
impl ChunkedWriter
Sourcepub async fn from_file<P: AsRef<Path>>(
path: P,
strategy: ChunkStrategy,
buffer_size: usize,
max_concurrent_writes: usize,
) -> Result<Self>
pub async fn from_file<P: AsRef<Path>>( path: P, strategy: ChunkStrategy, buffer_size: usize, max_concurrent_writes: usize, ) -> Result<Self>
Create a new chunked writer to a file.
Sourcepub fn set_total_chunks(self, n: usize) -> Self
pub fn set_total_chunks(self, n: usize) -> Self
Declare the expected total number of chunks up front.
When finalize is called it verifies that exactly n chunks were
written. A mismatch returns StreamingError::IncompleteFinalize.
Sourcepub async fn write_chunk(&mut self, data: Bytes) -> Result<()>
pub async fn write_chunk(&mut self, data: Bytes) -> Result<()>
Write a chunk of data.
Sourcepub async fn write_chunks(&mut self, chunks: Vec<Bytes>) -> Result<()>
pub async fn write_chunks(&mut self, chunks: Vec<Bytes>) -> Result<()>
Write multiple chunks sequentially.
Sourcepub async fn finalize(self) -> Result<()>
pub async fn finalize(self) -> Result<()>
Finalize the writer, validate chunk counts, and close the stream.
If set_total_chunks was called previously and the actual number of
chunks written does not match the preset value,
StreamingError::IncompleteFinalize is returned before the
underlying I/O is closed so callers can inspect the partial output.
After a successful finalize a footer descriptor containing the real
total_chunks value is appended so readers can discover the count
without having to re-scan the file.
Sourcepub fn chunks_written(&self) -> usize
pub fn chunks_written(&self) -> usize
Get the number of chunks written so far.
Sourcepub fn bytes_written(&self) -> u64
pub fn bytes_written(&self) -> u64
Get the total bytes written so far.