pub struct StreamingFileWriter { /* private fields */ }Expand description
Async buffered disk writer that streams data directly to a temporary .lanflare-part file
while concurrently calculating the SHA-256 hash incrementally in memory.
Implementations§
Source§impl StreamingFileWriter
impl StreamingFileWriter
Sourcepub async fn create(
target_path: impl Into<PathBuf>,
expected_size: Option<u64>,
expected_sha256: Option<String>,
) -> Result<Self, StorageError>
pub async fn create( target_path: impl Into<PathBuf>, expected_size: Option<u64>, expected_sha256: Option<String>, ) -> Result<Self, StorageError>
Creates a new streaming file writer. Overwrites target file if it already exists.
Sourcepub async fn create_with_overwrite(
target_path: impl Into<PathBuf>,
expected_size: Option<u64>,
expected_sha256: Option<String>,
allow_overwrite: bool,
) -> Result<Self, StorageError>
pub async fn create_with_overwrite( target_path: impl Into<PathBuf>, expected_size: Option<u64>, expected_sha256: Option<String>, allow_overwrite: bool, ) -> Result<Self, StorageError>
Creates a new streaming file writer with optional overwrite protection.
Sourcepub async fn create_with_capacity(
target_path: impl Into<PathBuf>,
expected_size: Option<u64>,
expected_sha256: Option<String>,
buffer_capacity: usize,
) -> Result<Self, StorageError>
pub async fn create_with_capacity( target_path: impl Into<PathBuf>, expected_size: Option<u64>, expected_sha256: Option<String>, buffer_capacity: usize, ) -> Result<Self, StorageError>
Creates a new streaming file writer with custom buffer capacity.
Sourcepub fn target_path(&self) -> &Path
pub fn target_path(&self) -> &Path
Returns the target destination path.
Sourcepub fn bytes_written(&self) -> u64
pub fn bytes_written(&self) -> u64
Returns the total number of bytes written so far.
Sourcepub fn expected_size(&self) -> Option<u64>
pub fn expected_size(&self) -> Option<u64>
Returns the expected size in bytes, if specified.
Sourcepub fn expected_sha256(&self) -> Option<&str>
pub fn expected_sha256(&self) -> Option<&str>
Returns the expected SHA-256 hash, if specified.
Sourcepub async fn write_chunk(&mut self, chunk: &[u8]) -> Result<(), StorageError>
pub async fn write_chunk(&mut self, chunk: &[u8]) -> Result<(), StorageError>
Writes a single chunk to disk and updates the running SHA-256 digest.
Sourcepub async fn write_all_from_stream<S, B, E>(
&mut self,
stream: S,
) -> Result<(), StorageError>
pub async fn write_all_from_stream<S, B, E>( &mut self, stream: S, ) -> Result<(), StorageError>
Streams chunks from an asynchronous stream and writes them directly to disk.
Sourcepub async fn write_all_from_reader<R>(
&mut self,
reader: R,
) -> Result<(), StorageError>
pub async fn write_all_from_reader<R>( &mut self, reader: R, ) -> Result<(), StorageError>
Reads all data from an AsyncRead source and writes it to disk.
Sourcepub async fn commit(self) -> Result<StorageCommitResult, StorageError>
pub async fn commit(self) -> Result<StorageCommitResult, StorageError>
Flushes data, verifies size and SHA-256 checksum, and atomically renames
the temporary .lanflare-part file to the final destination path.
Sourcepub async fn abort(self) -> Result<(), StorageError>
pub async fn abort(self) -> Result<(), StorageError>
Aborts writing and immediately removes the temporary file from disk.