Skip to content

Commit

Permalink
use stream instead of buffer for uploading artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Oct 6, 2023
1 parent 976e97a commit 0b33eef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
11 changes: 9 additions & 2 deletions src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ pub async fn download(

let output_get_res = output_get_req.get().await?;

assert!(output_get_res.status().is_success(), "Build artifacts could not be downloaded.");
assert!(
output_get_res.status().is_success(),
"Build artifacts could not be downloaded."
);

println!("Build artifacts downloaded");

let buf = &output_get_res.bytes().await?.to_vec();

assert!(vercel_cache_helper::utils::is_zstd_compressed(&buf), "Downloaded archive (Size: {}) is not zstd compressed.", &buf.len());
assert!(
vercel_cache_helper::utils::is_zstd_compressed(&buf),
"Downloaded archive (Size: {}) is not zstd compressed.",
&buf.len()
);

output_dir_archive.write_all(buf)?;

Expand Down
10 changes: 7 additions & 3 deletions src/commands/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ pub async fn upload(

pb.set_message("Uploading artfiacts...");

let res = output_put_req
.buffer(&mut output_archive_buf, output_archive_size)
let mut output_archive_cursor = std::io::Cursor::new(output_archive_buf);
let response = output_put_req
.stream(&mut output_archive_cursor, output_archive_size)
.await?;

assert!(res.status().is_success(), "Could not upload artifacts.");
if !response.status().is_success() {
println!("Could not upload artifacts.");
return Ok(());
}

pb.finish_with_message("Artifacts uploaded successfully.");

Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ async fn main() -> vercel_cache_helper::Result<()> {

let remote_client = vercel_cache_helper::get_remote_client(token, Some(team_id), product);

println!("🚀 fastn Vercel Cache Helper v{}", env!("CARGO_PKG_VERSION"));
println!(
"🚀 fastn Vercel Cache Helper v{}",
env!("CARGO_PKG_VERSION")
);

let result_future: std::pin::Pin<
Box<dyn std::future::Future<Output = Result<(), vercel_cache_helper::Error>>>,
Expand Down
7 changes: 1 addition & 6 deletions src/vercel/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl ArtifactPutRequest {

let headers = self.0.get_headers("PUT", Some(content_len));


let response = client
.put(&self.0.url)
.headers(headers)
Expand Down Expand Up @@ -148,11 +147,7 @@ impl ArtifactGetRequest {

let headers = self.0.get_headers("GET", None);

let response = client
.get(&self.0.url)
.headers(headers)
.send()
.await?;
let response = client.get(&self.0.url).headers(headers).send().await?;

Ok(response)
}
Expand Down

0 comments on commit 0b33eef

Please sign in to comment.