MCPcopy Create free account
hub / github.com/cargo-lambda/cargo-lambda / download_zip_template

Function download_zip_template

crates/cargo-lambda-new/src/template.rs:183–204  ·  view source on GitHub ↗
(url: &str, template_root: &Path)

Source from the content-addressed store, hash-verified

181
182#[tracing::instrument(target = "cargo_lambda")]
183async fn download_zip_template(url: &str, template_root: &Path) -> Result<PathBuf> {
184 tracing::debug!("downloading template");
185
186 let response = reqwest::get(url).await.into_diagnostic()?;
187 if response.status() != reqwest::StatusCode::OK {
188 return Err(miette::miette!(
189 "error downloading template from {} - {}",
190 url,
191 response.text().await.into_diagnostic()?
192 ));
193 }
194
195 let mut bytes = Cursor::new(response.bytes().await.into_diagnostic()?);
196
197 let tmp_file = template_root.join("cargo-lambda-template.zip");
198 let mut writer = File::create(&tmp_file)
199 .into_diagnostic()
200 .wrap_err_with(|| format!("unable to create file: {:?}", &tmp_file))?;
201 copy(&mut bytes, &mut writer).into_diagnostic()?;
202
203 Ok(tmp_file)
204}
205
206#[tracing::instrument(target = "cargo_lambda")]
207fn unzip_template(file: &Path, path: &Path) -> Result<PathBuf> {

Callers 1

expandMethod · 0.85

Calls 2

newFunction · 0.85
createFunction · 0.85

Tested by

no test coverage detected