5
0
mirror of git://git.proxmox.com/git/pxar.git synced 2025-01-03 09:17:38 +03:00

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 <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-03-12 15:03:41 +01:00
parent 675ecff32f
commit e5b9854989

View File

@ -563,15 +563,18 @@ impl<I: SeqRead> DecoderImpl<I> {
// //
async fn skip_entry(&mut self, offset: u64) -> io::Result<()> { 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(); let scratch = scratch_buffer();
while len >= (scratch.len() as u64) { while len >= (scratch.len()) {
seq_read_exact(&mut self.input, scratch).await?; seq_read_exact(input, scratch).await?;
len -= scratch.len() as u64; len -= scratch.len();
} }
let len = len as usize;
if len > 0 { if len > 0 {
seq_read_exact(&mut self.input, &mut scratch[..len]).await?; seq_read_exact(input, &mut scratch[..len]).await?;
} }
Ok(()) Ok(())
} }