Skip to content

Commit

Permalink
fixed buffer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Sep 27, 2023
1 parent 5b541ac commit 6a20855
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
16 changes: 9 additions & 7 deletions src/commands/upload.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::io::Read;
use std::io::{Read, Seek};

pub async fn upload(
remote_client: vercel_cache_helper::vercel::remote_cache_client::RemoteClient,
Expand Down Expand Up @@ -26,17 +26,19 @@ pub async fn upload(
vercel_cache_helper::utils::create_tar_gz_archive(&cache_dir, &cache_dir_archive)?;
vercel_cache_helper::utils::create_tar_gz_archive(&build_dir, &build_dir_archive)?;

build_dir_archive.seek(std::io::SeekFrom::Start(0)).unwrap();
cache_dir_archive.seek(std::io::SeekFrom::Start(0)).unwrap();

let mut build_archive_buf: Vec<u8> = Vec::new();
let mut cache_archive_buf: Vec<u8> = Vec::new();

build_dir_archive.read_to_end(&mut build_archive_buf)?;
cache_dir_archive.read_to_end(&mut cache_archive_buf)?;
println!("{:?}", build_dir_archive.metadata());

let build_archive_size = build_dir_archive.metadata()?.len();
let cache_archive_size = cache_dir_archive.metadata()?.len();
let build_archive_size = build_dir_archive.read_to_end(&mut build_archive_buf)?;
let cache_archive_size = cache_dir_archive.read_to_end(&mut cache_archive_buf)?;

println!("Build archive size: {} bytes", build_archive_size);
println!("Cache archive size: {} bytes", cache_archive_size);
println!("Build archive bytes read: {} bytes", build_archive_size);
println!("Cache archive bytes read: {} bytes", cache_archive_size);

let build_archive_hash = vercel_cache_helper::utils::generate_hash(&build_archive_buf);
let cache_dir_hash = vercel_cache_helper::utils::generate_hash(&cache_archive_buf);
Expand Down
20 changes: 15 additions & 5 deletions src/vercel/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub struct ArtifactOptions {
}

trait RequestHeaders {
fn get_headers(&self, method: &str, content_len: Option<u64>) -> reqwest::header::HeaderMap;
fn get_headers(&self, method: &str, content_len: Option<usize>) -> reqwest::header::HeaderMap;
}

// Define the base struct with common fields and behavior.
Expand Down Expand Up @@ -33,7 +33,7 @@ impl ArtifactBaseRequest {

// Implement the trait for the base struct.
impl RequestHeaders for ArtifactBaseRequest {
fn get_headers(&self, method: &str, content_len: Option<u64>) -> reqwest::header::HeaderMap {
fn get_headers(&self, method: &str, content_len: Option<usize>) -> reqwest::header::HeaderMap {
let mut headers = reqwest::header::HeaderMap::new();

headers.insert(
Expand Down Expand Up @@ -108,9 +108,13 @@ impl ArtifactPutRequest {

artifact.read_to_end(&mut body).await?;

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

println!("Headers: {:?}", headers);

let response = client
.put(&self.0.url)
.headers(self.0.get_headers("PUT", None))
.headers(headers)
.body(body)
.send()
.await?;
Expand All @@ -121,13 +125,19 @@ impl ArtifactPutRequest {
pub async fn buffer(
&mut self,
artifact: &mut [u8],
content_len: u64
content_len: usize
) -> vercel_cache_helper::Result<reqwest::Response> {
let client = reqwest::Client::new();

println!("{:?}", &artifact);

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

println!("Headers: {:?}", headers);

let response = client
.put(&self.0.url)
.headers(self.0.get_headers("PUT", Some(content_len)))
.headers(headers)
.body(artifact.to_owned())
.send()
.await?;
Expand Down

0 comments on commit 6a20855

Please sign in to comment.