Skip to content

Commit d819d0b

Browse files
authored
Fixing RemoteClient XORB upload (#12)
* Fixing upload * fixing merge
1 parent 539a4fc commit d819d0b

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

cas_client/src/remote_client.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::io::{Cursor, Write};
1+
use std::io::{BufWriter, Cursor, Write};
22

33
use anyhow::anyhow;
44
use bytes::Buf;
@@ -46,7 +46,7 @@ impl Client for RemoteClient {
4646
hash: *hash,
4747
};
4848

49-
let was_uploaded = self.client.upload(&key, data, chunk_boundaries).await?;
49+
let was_uploaded = self.client.upload(&key, &data, chunk_boundaries).await?;
5050

5151
if !was_uploaded {
5252
debug!("{key:?} not inserted into CAS.");
@@ -157,22 +157,27 @@ impl CASAPIClient {
157157
Ok(Some(length))
158158
}
159159

160-
pub async fn upload<T: Into<reqwest::Body>>(
160+
pub async fn upload(
161161
&self,
162162
key: &Key,
163-
contents: T,
163+
contents: &[u8],
164164
chunk_boundaries: Vec<u64>,
165165
) -> Result<bool> {
166-
let chunk_boundaries_query = chunk_boundaries
167-
.iter()
168-
.map(|num| num.to_string())
169-
.collect::<Vec<String>>()
170-
.join(",");
171-
let url = Url::parse(&format!("{0}/{1}/xorb/{key}?{chunk_boundaries_query}", self.scheme, self.endpoint))?;
166+
let url = Url::parse(&format!("{0}/{1}/xorb/{key}", self.scheme, self.endpoint))?;
167+
168+
let writer = Cursor::new(Vec::new());
169+
let mut buf = BufWriter::new(writer);
170+
171+
let (_,_) = CasObject::serialize(
172+
&mut buf,
173+
&key.hash,
174+
contents,
175+
&chunk_boundaries.into_iter().map(|x| x as u32).collect()
176+
)?;
172177

173178
debug!("Upload: POST to {url:?} for {key:?}");
174179

175-
let response = self.client.post(url).body(contents.into()).send().await?;
180+
let response = self.client.post(url).body(buf.buffer().to_vec()).send().await?;
176181
let response_body = response.bytes().await?;
177182
let response_parsed: UploadXorbResponse = serde_json::from_reader(response_body.reader())?;
178183

@@ -189,6 +194,7 @@ impl CASAPIClient {
189194
}
190195

191196
async fn reconstruct<W: Write>(&self, reconstruction_response: QueryReconstructionResponse, writer: &mut W) -> Result<usize> {
197+
192198
let info = reconstruction_response.reconstruction;
193199
let total_len = info.iter().fold(0, |acc, x| acc + x.unpacked_length);
194200
let futs = info.into_iter().map(|term| {

0 commit comments

Comments
 (0)