use crate::error::Error;
use crate::platform;
use crate::platform::ffi;
use std::path::Path;
pub struct ContentWriter {
handle: ffi::CzContentWriter,
}
unsafe impl Send for ContentWriter {}
impl ContentWriter {
pub fn new(base: &Path) -> Result<Self, Error> {
let outcome = platform::outcome(
ffi::cz_content_writer_new(&base.display().to_string()),
format!("write content into {}", base.display()),
)?;
Ok(Self {
handle: outcome.content_writer(),
})
}
pub fn create(&self, from: &Path) -> Result<(i64, String), Error> {
let outcome = platform::outcome(
self.handle.create(&from.display().to_string()),
format!("write {} as content", from.display()),
)?;
Ok((outcome.written_size(), outcome.written_digest()))
}
}