Closed devklick closed 2 months ago
I've simplified the example, because the problem happens even if you manually download the zip file to the working directory and then try to unzip it with async-zip.
use std::{env, path::PathBuf};
use async_zip::base::read::seek::ZipFileReader;
use tokio::io::{AsyncWriteExt, BufReader};
use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt};
#[tokio::main]
async fn main() {
let zip_path = env::current_dir()
.unwrap()
.join("Godot_v4.3-stable_linux.x86_64.zip");
let unzipped_path = zip_path
.clone()
.parent()
.unwrap()
.join(zip_path.file_stem().unwrap());
let file = tokio::fs::File::open(zip_path)
.await
.expect("Error reading zip file");
unzip_file(file, unzipped_path).await;
}
async fn unzip_file(file: tokio::fs::File, target: PathBuf) {
let archive = BufReader::new(file).compat();
let mut reader = ZipFileReader::new(archive)
.await
.expect("Error creating zip reader");
// ^^ Error creating zip reader: CompressionNotSupported(8)
// rest omitted for brevity
}
I think this is pretty much doing the exact same thing as the example here, but I still cant figure out why this isnt working.
I was missing the deflate
feature. Adding this feature solved the problem.
cargo add async_zip --features deflate
I'm downloading a zip file then trying to extract it using async-zip, but I'm hitting a
CompressionNotSupported(8)
error when callingZipFileReader::new
. I'm hoping you might be able to help understand what the problem is here.Code to reproduce:
main.rs
```rs use std::{env, path::PathBuf}; use async_zip::base::read::seek::ZipFileReader; use reqwest::Url; use tokio::io::{AsyncWriteExt, BufReader}; use tokio_util::compat::{TokioAsyncReadCompatExt, TokioAsyncWriteCompatExt}; #[tokio::main] async fn main() { let url = Url::parse("https://github.com/godotengine/godot/releases/download/4.3-stable/Godot_v4.3-stable_linux.x86_64.zip").unwrap(); let zip_path = env::current_dir().unwrap().join("test.zip"); let unzipped_path = zip_path .clone() .parent() .unwrap() .join(zip_path.file_stem().unwrap()); let file = download_file(url, &zip_path).await; unzip_file(file, unzipped_path).await; } async fn download_file(url: Url, zip_path: &PathBuf) -> tokio::fs::File { let mut file = tokio::fs::File::options() .read(true) .write(true) .create(true) .open(&zip_path) .await .expect("Failed to create file"); let request = reqwest::Client::new().get(url); let mut download = request.send().await.expect("Error downloading file"); while let Some(chunk) = download.chunk().await.expect("Error downloading chunk") { file.write(&chunk) .await .expect("Error writing chunk to file"); } file.flush().await.expect("Error flushing file"); return file; } async fn unzip_file(file: tokio::fs::File, target: PathBuf) { let archive = BufReader::new(file).compat(); let mut reader = ZipFileReader::new(archive) .await .expect("Error creating zip reader"); // ^^ Error creating zip reader: CompressionNotSupported(8) // rest omitted for brevity } ```Cargo.toml
```toml [package] name = "debug-async-zip" version = "0.1.0" edition = "2021" [dependencies] async_zip = { version = "0.0.17", features = ["tokio", "tokio-fs"] } reqwest = "0.12.7" tokio = { version = "1.40.0", features = ["full"] } tokio-util = "0.7.12" ```I've been trying to use the file extraction example for reference. I'm a bit confused by the various
ZipFileReader
's that exist, and wonder if I've got the wrong one. I have tried all of them, and they either dont compile due to an error likethe trait bound ``Compat<tokio::io::BufReader<tokio::fs::File>>: AsRef<Path>`` is not satisfied
(which is the case when usingasync_zip::tokio::read::fs::ZipFileReader
), or they compile but hit this runtime error.Any help to understand this error and how to fix it would be appreciated.
I've been able to successfully extract this archive synchronously using zip, so I dont think it's an issue with the archive.
Example using zip
```rs // main... // unzip_file(file, unzipped_path).await; unzip_file_sync(file.try_into_std().unwrap(), unzipped_path); fn unzip_file_sync(file: fs::File, target: PathBuf) { let mut archive = zip::ZipArchive::new(file).expect("Error creating zip reader"); archive.extract(target).expect("Error extracting zip file"); } ```