From e444dbf0113a763a233523bcdd0a2d449686a15d Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 8 May 2026 15:03:40 -0600 Subject: [PATCH] Actually remove file (#56223) Accidentally added in 7205fb9c71cc28e5488c0db171e15088146c310e Release Notes: - N/A --- crates/reqwest_client/examples/download.rs | 75 ---------------------- 1 file changed, 75 deletions(-) delete mode 100644 crates/reqwest_client/examples/download.rs diff --git a/crates/reqwest_client/examples/download.rs b/crates/reqwest_client/examples/download.rs deleted file mode 100644 index 63cdaada628cd2674ca5b9a4e783b8b37588c7f5..0000000000000000000000000000000000000000 --- a/crates/reqwest_client/examples/download.rs +++ /dev/null @@ -1,75 +0,0 @@ -use std::time::Instant; - -use anyhow::{Context as _, Result, anyhow}; -use futures::AsyncReadExt as _; -use http_client::{AsyncBody, HttpClient as _}; -use reqwest_client::ReqwestClient; - -fn main() -> Result<()> { - let url = std::env::args() - .nth(1) - .ok_or_else(|| anyhow!("usage: cargo run -p reqwest_client --example download -- "))?; - - let client = ReqwestClient::user_agent("zed-reqwest-client-download-example")?; - - futures::executor::block_on(async move { - let started_at = Instant::now(); - let mut response = client - .get(&url, AsyncBody::empty(), true) - .await - .with_context(|| format!("requesting {url}"))?; - let headers_elapsed = started_at.elapsed(); - - println!("status: {}", response.status()); - println!("version: {:?}", response.version()); - if let Some(content_length) = response - .headers() - .get(http_client::http::header::CONTENT_LENGTH) - && let Ok(content_length) = content_length.to_str() - { - println!("content-length: {content_length}"); - } - println!("time-to-headers: {:.3}s", headers_elapsed.as_secs_f64()); - - let mut buffer = vec![0; 1024 * 1024]; - let mut bytes_downloaded = 0usize; - let body_started_at = Instant::now(); - - loop { - let bytes_read = response - .body_mut() - .read(&mut buffer) - .await - .context("reading response body")?; - if bytes_read == 0 { - break; - } - bytes_downloaded += bytes_read; - } - - let body_elapsed = body_started_at.elapsed(); - let total_elapsed = started_at.elapsed(); - let mebibytes = bytes_downloaded as f64 / 1024.0 / 1024.0; - let body_seconds = body_elapsed.as_secs_f64(); - let total_seconds = total_elapsed.as_secs_f64(); - - println!("downloaded-bytes: {bytes_downloaded}"); - println!("downloaded-mib: {mebibytes:.3}"); - println!("body-time: {body_seconds:.3}s"); - println!("total-time: {total_seconds:.3}s"); - if body_seconds > 0.0 { - println!("body-throughput: {:.3} MiB/s", mebibytes / body_seconds); - } - if total_seconds > 0.0 { - println!("total-throughput: {:.3} MiB/s", mebibytes / total_seconds); - } - - anyhow::ensure!( - response.status().is_success(), - "download completed with unsuccessful status {}", - response.status() - ); - - Ok(()) - }) -}