From 95c85c127a8c646591069df8ca92247529f5afe6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 3 May 2021 22:42:04 +0100 Subject: [PATCH] provide DigestWrite::of Signed-off-by: Ian Jackson --- src/bin/otter.rs | 7 ++----- src/utils.rs | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index b8553adf..f9c9457f 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -1341,11 +1341,8 @@ mod upload_bundle { .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 { diff --git a/src/utils.rs b/src/utils.rs index 438984ff..00f3c836 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -584,6 +584,13 @@ impl DigestWrite { } impl DigestWrite { pub fn sink() -> Self { DigestWrite::new(io::sink()) } + + #[throws(io::Error)] + pub fn of(r: &mut R) -> digest::Output where R: Read { + let mut dw = DigestWrite::::sink(); + io::copy(r, &mut dw)?; + dw.finish().0 + } } impl Write for DigestWrite { -- 2.30.2