summaryrefslogtreecommitdiff
path: root/crates/typst-cli
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-cli')
-rw-r--r--crates/typst-cli/src/download.rs10
-rw-r--r--crates/typst-cli/src/update.rs4
2 files changed, 10 insertions, 4 deletions
diff --git a/crates/typst-cli/src/download.rs b/crates/typst-cli/src/download.rs
index 9db73fe8..e5a97cda 100644
--- a/crates/typst-cli/src/download.rs
+++ b/crates/typst-cli/src/download.rs
@@ -37,6 +37,13 @@ static TLS_CONFIG: Lazy<Option<Arc<rustls::ClientConfig>>> = Lazy::new(|| {
/// Download binary data and display its progress.
#[allow(clippy::result_large_err)]
pub fn download_with_progress(url: &str) -> Result<Vec<u8>, ureq::Error> {
+ let response = download(url)?;
+ Ok(RemoteReader::from_response(response).download()?)
+}
+
+/// Download from a URL.
+#[allow(clippy::result_large_err)]
+pub fn download(url: &str) -> Result<ureq::Response, ureq::Error> {
let mut builder = ureq::AgentBuilder::new()
.user_agent(concat!("typst/{}", env!("CARGO_PKG_VERSION")));
@@ -54,8 +61,7 @@ pub fn download_with_progress(url: &str) -> Result<Vec<u8>, ureq::Error> {
}
let agent = builder.build();
- let response = agent.get(url).call()?;
- Ok(RemoteReader::from_response(response).download()?)
+ agent.get(url).call()
}
/// A wrapper around [`ureq::Response`] that reads the response body in chunks
diff --git a/crates/typst-cli/src/update.rs b/crates/typst-cli/src/update.rs
index 95418d03..f3a75163 100644
--- a/crates/typst-cli/src/update.rs
+++ b/crates/typst-cli/src/update.rs
@@ -11,7 +11,7 @@ use xz2::bufread::XzDecoder;
use zip::ZipArchive;
use crate::args::UpdateCommand;
-use crate::download::download_with_progress;
+use crate::download::{download, download_with_progress};
const TYPST_GITHUB_ORG: &str = "typst";
const TYPST_REPO: &str = "typst";
@@ -111,7 +111,7 @@ impl Release {
),
};
- match ureq::get(&url).call() {
+ match download(&url) {
Ok(response) => response
.into_json()
.map_err(|err| eco_format!("unable to parse JSON response: {err}")),