hoist item declarations above statements
This commit is contained in:
@@ -67,18 +67,20 @@ pub(crate) async fn download_to<F>(url: &str, dest: &Path, mut on_progress: F) -
|
||||
where
|
||||
F: FnMut(u64, Option<u64>) + Send,
|
||||
{
|
||||
use std::io::Write;
|
||||
|
||||
if let Some(parent) = dest.parent() {
|
||||
std::fs::create_dir_all(parent).context("creating update parent dir")?;
|
||||
}
|
||||
let client = reqwest::Client::builder()
|
||||
.user_agent(concat!("ByteSize/", env!("CARGO_PKG_VERSION")))
|
||||
.build()?;
|
||||
|
||||
let resp = client.get(url).send().await?.error_for_status()?;
|
||||
let total = resp.content_length();
|
||||
let mut downloaded = 0u64;
|
||||
let mut stream = resp.bytes_stream();
|
||||
let mut file = std::fs::File::create(dest).context("creating update file")?;
|
||||
use std::io::Write;
|
||||
while let Some(chunk) = stream.next().await {
|
||||
let chunk = chunk?;
|
||||
file.write_all(&chunk)?;
|
||||
|
||||
Reference in New Issue
Block a user