diff --git a/src/get.rs b/src/get.rs index 1035c33..473aaf1 100644 --- a/src/get.rs +++ b/src/get.rs @@ -7,6 +7,11 @@ use crate::content::read::{self, Reader}; use crate::errors::Error; use crate::index::{self, Entry}; +/// File handle for reading from a content entry. +/// +/// Make sure to call `get.check()` when done reading +/// to verify that the extracted data passes integrity +/// verification. pub struct Get { reader: Reader, } @@ -18,11 +23,16 @@ impl std::io::Read for Get { } impl Get { + /// Checks that data read from disk passes integrity checks. Returns the + /// algorithm that was used verified the data. Should be called only after + /// all data has been read from disk. pub fn check(self) -> Result { self.reader.check() } } +/// Opens a new file handle into the cache, looking it up in the index using +/// `key`. pub fn open(cache: P, key: K) -> Result where P: AsRef, @@ -35,6 +45,7 @@ where } } +/// Opens a new file handle into the cache, based on its integrity address. pub fn open_hash

(cache: P, sri: Integrity) -> Result where P: AsRef, @@ -44,6 +55,8 @@ where }) } +/// Reads the entire contents of a cache file into a bytes vector, looking the +/// data up by key. pub fn read(cache: P, key: K) -> Result, Error> where P: AsRef, @@ -56,6 +69,8 @@ where } } +/// Reads the entire contents of a cache file into a bytes vector, looking the +/// data up by its content address. pub fn read_hash

(cache: P, sri: &Integrity) -> Result, Error> where P: AsRef, @@ -63,6 +78,7 @@ where Ok(read::read(cache.as_ref(), sri)?) } +/// Copies a cache entry by key to a specified location. pub fn copy(cache: P, key: K, to: Q) -> Result where P: AsRef, @@ -76,6 +92,7 @@ where } } +/// Copies a cache entry by integrity address to a specified location. pub fn copy_hash(cache: P, sri: &Integrity, to: Q) -> Result where P: AsRef, @@ -84,6 +101,7 @@ where read::copy(cache.as_ref(), sri, to.as_ref()) } +/// Gets entry information and metadata for a certain key. pub fn info(cache: P, key: K) -> Result, Error> where P: AsRef, @@ -92,6 +110,7 @@ where index::find(cache.as_ref(), key.as_ref()) } +/// Returns true if the given hash exists in the cache. pub fn hash_exists>(cache: P, sri: &Integrity) -> bool { read::has_content(cache.as_ref(), &sri).is_some() }