Fetch CAS blobs over Iroh
This commit is contained in:
parent
d5a548182b
commit
e4b788fec2
10 changed files with 425 additions and 19 deletions
|
|
@ -244,6 +244,14 @@ impl LocalCas {
|
|||
std::fs::copy(path, out).map_err(CasError::from)
|
||||
}
|
||||
|
||||
pub fn read_bytes(&self, hash: &BlobHash) -> Result<Vec<u8>, CasError> {
|
||||
let path = self.blob_path(hash)?;
|
||||
if !path.exists() {
|
||||
return Err(CasError::NotFound(hash.to_string()));
|
||||
}
|
||||
Ok(std::fs::read(path)?)
|
||||
}
|
||||
|
||||
pub fn has(&self, hash: &BlobHash) -> Result<bool, CasError> {
|
||||
Ok(self.blob_path(hash)?.exists())
|
||||
}
|
||||
|
|
@ -547,6 +555,10 @@ mod tests {
|
|||
let out = dir.path().join("out.txt");
|
||||
cas.get_to_path(&info.hash, &out).expect("get");
|
||||
assert_eq!(std::fs::read(out).expect("read"), b"hello geth");
|
||||
assert_eq!(
|
||||
cas.read_bytes(&info.hash).expect("read bytes"),
|
||||
b"hello geth"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue