From e5b98549898ca214414791cd4f0edde5563e07f8 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Tue, 12 Mar 2024 15:03:41 +0100 Subject: [PATCH] decoder: factor out skip part from skip_entry Make the skip part reusable for a different input. In preparation for skipping payload paddings in a separated input. Signed-off-by: Christian Ebner --- src/decoder/mod.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index d1fb911..3c6d9ef 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -563,15 +563,18 @@ impl DecoderImpl { // async fn skip_entry(&mut self, offset: u64) -> io::Result<()> { - let mut len = self.current_header.content_size() - offset; + let len = (self.current_header.content_size() - offset) as usize; + Self::skip(&mut self.input, len).await + } + + async fn skip(input: &mut I, mut len: usize) -> io::Result<()> { let scratch = scratch_buffer(); - while len >= (scratch.len() as u64) { - seq_read_exact(&mut self.input, scratch).await?; - len -= scratch.len() as u64; + while len >= (scratch.len()) { + seq_read_exact(input, scratch).await?; + len -= scratch.len(); } - let len = len as usize; if len > 0 { - seq_read_exact(&mut self.input, &mut scratch[..len]).await?; + seq_read_exact(input, &mut scratch[..len]).await?; } Ok(()) }