use super::ArchiveWriter;
use super::WriteEntry;
use crate::error::Error;
use crate::platform;
use crate::platform::ffi;
use std::fmt;
use std::marker::PhantomData;
pub struct ArchiveWriterTransaction<'a> {
pub(super) handle: ffi::CzArchiveWriterTransaction,
pub(super) writer: PhantomData<&'a ArchiveWriter>,
}
impl fmt::Debug for ArchiveWriterTransaction<'_> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter
.debug_struct("ArchiveWriterTransaction")
.finish_non_exhaustive()
}
}
impl ArchiveWriterTransaction<'_> {
pub fn write_header(&self, entry: &WriteEntry) -> Result<(), Error> {
platform::outcome(
self.handle.write_header(entry.handle.duplicate()),
format!("write the header of {} to an archive", entry.path().unwrap_or_default()),
)
.map(drop)
}
pub fn write_chunk(&self, data: &[u8]) -> Result<(), Error> {
platform::outcome(self.handle.write_chunk(data.to_vec()), "write a chunk to an archive").map(drop)
}
pub fn finish(&self) -> Result<(), Error> {
platform::outcome(self.handle.finish(), "finish an archive entry").map(drop)
}
}