hoist item declarations above statements

This commit is contained in:
2026-09-21 01:17:28 +03:00
parent 8972592b8d
commit 72f24b7369
3 changed files with 33 additions and 25 deletions
+3 -1
View File
@@ -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)?;