Bump async_zip from 0.0.9 to 0.0.10 (#709)

* Bump async_zip from 0.0.9 to 0.0.10

Bumps [async_zip](https://github.com/Majored/rs-async-zip) from 0.0.9 to 0.0.10.
- [Release notes](https://github.com/Majored/rs-async-zip/releases)
- [Commits](https://github.com/Majored/rs-async-zip/compare/v0.0.9...v0.0.10)

---
updated-dependencies:
- dependency-name: async_zip
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

* Fix usage of `async_zip::read::stream` APIs


Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
dependabot[bot] 2023-01-16 14:26:08 +11:00 committed by GitHub
parent bc6ac734b4
commit 7cd782271e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 152 deletions

View file

@ -12,7 +12,7 @@ license = "GPL-3.0"
[dependencies]
async-trait = "0.1.61"
async-compression = { version = "0.3.15", features = ["gzip", "zstd", "xz", "bzip2", "tokio"] }
async_zip = { version = "0.0.9", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
async_zip = { version = "0.0.10", features = ["deflate", "bzip2", "lzma", "zstd", "xz"] }
binstalk-types = { version = "0.2.0", path = "../binstalk-types" }
bytes = "1.3.0"
bzip2 = "0.4.4"

View file

@ -48,8 +48,10 @@ where
let mut zip = ZipFileReader::new(reader);
let mut buf = BytesMut::with_capacity(4 * 4096);
while let Some(entry) = zip.entry_reader().await.map_err(ZipError::from_inner)? {
extract_zip_entry(entry, path, &mut buf).await?;
while let Some(mut zip_reader) = zip.next_entry().await.map_err(ZipError::from_inner)? {
extract_zip_entry(&mut zip_reader, path, &mut buf).await?;
zip = zip_reader.done().await.map_err(ZipError::from_inner)?;
}
Ok(())

View file

@ -3,12 +3,15 @@ use std::{
path::{Component, Path, PathBuf},
};
use async_zip::{read::ZipEntryReader, ZipEntryExt};
use async_zip::read::{
seek::ZipEntryReader,
stream::{Reading, ZipFileReader},
};
use bytes::{Bytes, BytesMut};
use futures_util::future::{try_join, TryFutureExt};
use thiserror::Error as ThisError;
use tokio::{
io::{AsyncRead, AsyncReadExt},
io::{AsyncRead, AsyncReadExt, Take},
sync::mpsc,
};
@ -34,7 +37,7 @@ impl ZipError {
}
pub(super) async fn extract_zip_entry<R>(
entry: ZipEntryReader<'_, R>,
zip_reader: &mut ZipFileReader<Reading<'_, Take<R>>>,
path: &Path,
buf: &mut BytesMut,
) -> Result<(), DownloadError>
@ -42,7 +45,7 @@ where
R: AsyncRead + Unpin + Send + Sync,
{
// Sanitize filename
let raw_filename = entry.entry().filename();
let raw_filename = zip_reader.entry().filename();
let filename = check_filename_and_normalize(raw_filename)
.ok_or_else(|| ZipError(ZipErrorInner::InvalidFilePath(raw_filename.into())))?;
@ -56,7 +59,7 @@ where
{
use std::{fs::Permissions, os::unix::fs::PermissionsExt};
if let Some(mode) = entry.entry().unix_permissions() {
if let Some(mode) = zip_reader.entry().unix_permissions() {
let mode: u16 = mode;
perms = Some(Permissions::from_mode(mode as u32));
}
@ -98,7 +101,7 @@ where
Ok(())
})
.err_into(),
copy_file_to_mpsc(entry, tx, buf)
copy_file_to_mpsc(zip_reader.reader(), tx, buf)
.map_err(ZipError::from_inner)
.map_err(DownloadError::from),
)
@ -109,7 +112,7 @@ where
}
async fn copy_file_to_mpsc<R>(
mut entry: ZipEntryReader<'_, R>,
entry_reader: &mut ZipEntryReader<'_, R>,
tx: mpsc::Sender<Bytes>,
buf: &mut BytesMut,
) -> Result<(), async_zip::error::ZipError>
@ -118,7 +121,7 @@ where
{
// Since BytesMut does not have a max cap, if AsyncReadExt::read_buf returns
// 0 then it means Eof.
while entry.read_buf(buf).await? != 0 {
while entry_reader.read_buf(buf).await? != 0 {
// Ensure AsyncReadExt::read_buf can read at least 4096B to avoid
// frequent expensive read syscalls.
//
@ -143,11 +146,17 @@ where
}
}
if entry.compare_crc() {
// With async_zip 0.0.10, ZipEntryReader::compare_crc is removed.
// Hopefully it will restored later.
/*
if entry_reader.compare_crc() {
Ok(())
} else {
Err(async_zip::error::ZipError::CRC32CheckError)
}
}*/
Ok(())
}
/// Ensure the file path is safe to use as a [`Path`].