From 0a30154198fa39b0595889d053851074f4fa14b9 Mon Sep 17 00:00:00 2001 From: Zachary Dremann Date: Tue, 19 Mar 2024 22:01:39 -0400 Subject: [PATCH] Make use of CompressorImpl::extra_size --- crates/applesauce-core/src/compressor/mod.rs | 1 - crates/applesauce-core/src/compressor/zlib.rs | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/applesauce-core/src/compressor/mod.rs b/crates/applesauce-core/src/compressor/mod.rs index 4471a8e..b044f1f 100644 --- a/crates/applesauce-core/src/compressor/mod.rs +++ b/crates/applesauce-core/src/compressor/mod.rs @@ -21,7 +21,6 @@ mod zlib; pub(crate) trait CompressorImpl { /// The offset to start data at, for the specified number of blocks #[must_use] - fn header_size(block_count: u64) -> u64; #[must_use] diff --git a/crates/applesauce-core/src/compressor/zlib.rs b/crates/applesauce-core/src/compressor/zlib.rs index 397bb0c..181176d 100644 --- a/crates/applesauce-core/src/compressor/zlib.rs +++ b/crates/applesauce-core/src/compressor/zlib.rs @@ -131,6 +131,15 @@ impl super::CompressorImpl for Zlib { u32::try_from(writer.stream_position()?).map_err(|_| io::ErrorKind::InvalidInput)?; writer.write_all(&ZLIB_TRAILER)?; + // This is logically a non-modifying operation, even if it takes &mut self, and can fail + #[allow(clippy::debug_assert_with_mut_call)] + { + debug_assert_eq!( + writer.stream_position()?, + u64::from(data_end) + Self::extra_size(block_count.into()) + ); + } + writer.rewind()?; writer.write_all(&header(data_end))?;