我正在尝试下载和保存一个Zip文件。看起来下载正常,但保存时出现问题。如果我尝试解压缩文件,就会出现以下错误:
Archive: download.zip
error [download.zip]: missing 3208647056 bytes in zipfile
(attempting to process anyway)
error [download.zip]: attempt to seek before beginning of zipfile
(please check that you have transferred or created the zipfile in the
appropriate BINARY mode and that you have compiled UnZip properly)
这是我正在使用的代码:
cargo.toml
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = { version = "0.10"}
tokio = { version = "0.2", features = ["full"] }
error-chain = "0.12.2"
src/main.rs
use error_chain::error_chain;
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;
error_chain! {
foreign_links {
Io(std::io::Error);
HttpRequest(reqwest::Error);
}
}
#[tokio::main]
async fn main() -> Result<()> {
let target = "https://github.com/twbs/bootstrap/archive/v4.0.0.zip";
let response = reqwest::get(target).await?;
let path = Path::new("./download.zip");
let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}", why),
Ok(file) => file,
};
let content = response.text().await?;
file.write_all(content.as_bytes())?;
Ok(())
}
有人能帮我吗?
std
类型都是阻塞的,因此在这里实际上不会异步执行任何操作。 - mcarton