use super::{NamedWriteError, WriteOptions, write_with};
use ic_host_artifacts::artifact::{ArtifactIdentity, CopyError, Sha256Digest, copy_reader};
use std::path::Path;
pub fn copy_verified(
source: &Path,
destination: &Path,
expected: Sha256Digest,
max_bytes: u64,
options: WriteOptions,
) -> Result<ArtifactIdentity, NamedWriteError<CopyError>> {
write_with(destination, options, |sink| {
let source = crate::read::open_regular_file(source)?;
copy_reader(source, sink, max_bytes)?
.verify(expected)
.map_err(CopyError::Input)
})
}
#[cfg(test)]
mod tests;