diff --git a/examples/file_extraction.rs b/examples/file_extraction.rs index 474012e..451de1c 100644 --- a/examples/file_extraction.rs +++ b/examples/file_extraction.rs @@ -16,7 +16,10 @@ use std::{ }; use async_zip::base::read::seek::ZipFileReader; -use tokio::{fs::{create_dir_all, File, OpenOptions}, io::BufReader}; +use tokio::{ + fs::{create_dir_all, File, OpenOptions}, + io::BufReader, +}; use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; #[tokio::main] diff --git a/src/base/read/io/entry.rs b/src/base/read/io/entry.rs index e7b4829..a0395a9 100644 --- a/src/base/read/io/entry.rs +++ b/src/base/read/io/entry.rs @@ -9,7 +9,7 @@ use crate::spec::Compression; use std::pin::Pin; use std::task::{Context, Poll}; -use futures_lite::io::{AsyncRead, AsyncReadExt, Take, AsyncBufRead}; +use futures_lite::io::{AsyncBufRead, AsyncRead, AsyncReadExt, Take}; use pin_project::pin_project; /// A type which encodes that [`ZipEntryReader`] has associated entry data. diff --git a/src/base/read/io/mod.rs b/src/base/read/io/mod.rs index e219bc6..86af934 100644 --- a/src/base/read/io/mod.rs +++ b/src/base/read/io/mod.rs @@ -8,13 +8,21 @@ pub(crate) mod hashed; pub(crate) mod locator; pub(crate) mod owned; -use std::{future::Future, io::ErrorKind, pin::Pin, task::{ready, Context, Poll}}; +use std::{ + future::Future, + io::ErrorKind, + pin::Pin, + task::{ready, Context, Poll}, +}; pub use combined_record::CombinedCentralDirectoryRecord; use futures_lite::io::AsyncBufRead; use pin_project::pin_project; -use crate::{spec::consts::{DATA_DESCRIPTOR_LENGTH, DATA_DESCRIPTOR_SIGNATURE, SIGNATURE_LENGTH}, string::{StringEncoding, ZipString}}; +use crate::{ + spec::consts::{DATA_DESCRIPTOR_LENGTH, DATA_DESCRIPTOR_SIGNATURE, SIGNATURE_LENGTH}, + string::{StringEncoding, ZipString}, +}; use futures_lite::io::{AsyncRead, AsyncReadExt}; /// Read and return a dynamic length string from a reader which impls AsyncRead. diff --git a/src/base/read/mem.rs b/src/base/read/mem.rs index d31ffd2..c8fa9f1 100644 --- a/src/base/read/mem.rs +++ b/src/base/read/mem.rs @@ -76,7 +76,7 @@ use crate::file::ZipFile; use std::sync::Arc; -use futures_lite::io::{Cursor}; +use futures_lite::io::Cursor; use super::io::entry::{WithEntry, WithoutEntry}; diff --git a/src/base/read/mod.rs b/src/base/read/mod.rs index 269515a..e07cd16 100644 --- a/src/base/read/mod.rs +++ b/src/base/read/mod.rs @@ -222,7 +222,7 @@ where if header.flags.data_descriptor && compression == Compression::Stored { return Err(ZipError::FeatureNotSupported( - "stream reading entries with data descriptors & Stored compression mode", + "stream reading entries with data descriptors & Stored compression mode", )); } if header.flags.encrypted { diff --git a/src/base/read/stream.rs b/src/base/read/stream.rs index ea179c8..707f8f4 100644 --- a/src/base/read/stream.rs +++ b/src/base/read/stream.rs @@ -55,8 +55,8 @@ use crate::error::ZipError; #[cfg(feature = "tokio")] use crate::tokio::read::stream::Ready as TokioReady; -use futures_lite::io::AsyncReadExt; use futures_lite::io::AsyncBufRead; +use futures_lite::io::AsyncReadExt; #[cfg(feature = "tokio")] use tokio_util::compat::TokioAsyncReadCompatExt; @@ -92,7 +92,9 @@ where None => return Ok(None), }; - let reader = ZipEntryReader::new_with_owned(self.0.0, entry.compression, u64::MAX); + let length = if entry.data_descriptor { u64::MAX } else { entry.compressed_size }; + let reader = ZipEntryReader::new_with_owned(self.0 .0, entry.compression, length); + Ok(Some(ZipFileReader(Reading(reader, entry.data_descriptor)))) } @@ -103,7 +105,8 @@ where None => return Ok(None), }; - let reader = ZipEntryReader::new_with_owned(self.0.0, entry.compression, u64::MAX); + let length = if entry.data_descriptor { u64::MAX } else { entry.compressed_size }; + let reader = ZipEntryReader::new_with_owned(self.0 .0, entry.compression, length); let data_descriptor = entry.data_descriptor; Ok(Some(ZipFileReader(Reading(reader.into_with_entry_owned(entry), data_descriptor)))) @@ -149,7 +152,7 @@ where let mut inner = self.0 .0.into_inner(); // Has data descriptor. - if self.0.1 { + if self.0 .1 { ConsumeDataDescriptor(&mut inner).await?; } @@ -162,7 +165,7 @@ where let mut inner = self.0 .0.into_inner(); // Has data descriptor. - if self.0.1 { + if self.0 .1 { ConsumeDataDescriptor(&mut inner).await?; } diff --git a/src/tokio/read/fs.rs b/src/tokio/read/fs.rs index b69e6b9..c045d39 100644 --- a/src/tokio/read/fs.rs +++ b/src/tokio/read/fs.rs @@ -140,7 +140,10 @@ impl ZipFileReader { } /// Returns a new entry reader if the provided index is valid. - pub async fn reader_with_entry(&self, index: usize) -> Result>, WithEntry<'_>>> { + pub async fn reader_with_entry( + &self, + index: usize, + ) -> Result>, WithEntry<'_>>> { let stored_entry = self.inner.file.entries.get(index).ok_or(ZipError::EntryIndexOutOfBounds)?; let mut fs_file = BufReader::new(File::open(&self.inner.path).await?).compat();