Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
.with_context(|| args.bundle_file.clone())
.context("open bundle file")?;
let mut f = BufReader::new(f);
- let hash = {
- let mut dw = bundles::DigestWrite::sink();
- io::copy(&mut f, &mut dw).context("read bundle file (for hash)")?;
- dw.finish().0
- };
+ let hash = bundles::DigestWrite::of(&mut f)
+ .context("read bundle file (for hash)")?;
let kind = bundles::Kind::only();
f.rewind().context("rewind bundle file")?;
let cmd = MC::UploadBundle {
}
impl<D: Digest> DigestWrite<D, io::Sink> {
pub fn sink() -> Self { DigestWrite::new(io::sink()) }
+
+ #[throws(io::Error)]
+ pub fn of<R>(r: &mut R) -> digest::Output<D> where R: Read {
+ let mut dw = DigestWrite::<D,_>::sink();
+ io::copy(r, &mut dw)?;
+ dw.finish().0
+ }
}
impl<D: Digest, W: Write> Write for DigestWrite<D, W> {