diff --git a/mater/lib/src/multicodec.rs b/mater/lib/src/multicodec.rs index 5b8add0a7..8d06402c4 100644 --- a/mater/lib/src/multicodec.rs +++ b/mater/lib/src/multicodec.rs @@ -40,6 +40,6 @@ where } // Returns Some(data) if the CID is an identity. If not, None is returned. -pub fn is_identity(cid: &CidGeneric) -> Option<&[u8]> { - (cid.hash().code() == IDENTITY_CODE).then_some(cid.hash().digest()) +pub fn get_identity_data(cid: &CidGeneric) -> Option<&[u8]> { + (cid.hash().code() == IDENTITY_CODE).then(|| cid.hash().digest()) } diff --git a/mater/lib/src/stores/file.rs b/mater/lib/src/stores/file.rs index 57e02ec3a..fea9cdf41 100644 --- a/mater/lib/src/stores/file.rs +++ b/mater/lib/src/stores/file.rs @@ -10,7 +10,7 @@ use tokio::{ }; use crate::{ - multicodec::{is_identity, SHA_256_CODE}, + multicodec::{get_identity_data, SHA_256_CODE}, v1::{self, read_block, write_block}, v2::{self}, CarV1Header, CarV2Header, Characteristics, Error, Index, IndexEntry, MultihashIndexSorted, @@ -35,7 +35,7 @@ pub struct FileBlockstore { /// Inner file store. Encapsulating state that is locked and used together. struct FileBlockstoreInner { - /// Underlying data store in a car format + /// Underlying data store in a CAR format store: File, /// The byte length of the CARv1 payload. This is used by the indexing, so we /// know the locations of each blocks in the file. @@ -138,7 +138,7 @@ impl FileBlockstore { /// Check if the store contains a block with the cid. In case of IDENTITY /// CID it always returns true. pub async fn has(&self, cid: Cid) -> Result { - if is_identity(&cid).is_some() { + if get_identity_data(&cid).is_some() { return Ok(true); } @@ -150,11 +150,11 @@ impl FileBlockstore { /// from the cid is returned. pub async fn get(&self, cid: Cid) -> Result>, Error> { // If CID is an identity - if let Some(data) = is_identity(&cid) { + if let Some(data) = get_identity_data(&cid) { return Ok(Some(data.to_owned())); } - // The lock is hold through out the method execution. That way we are + // The lock is held throughout the method execution. That way we are // certain that the file is not used and we are moving the cursor back // to the correct place after the read. let mut inner = self.inner.write().await; @@ -186,7 +186,7 @@ impl FileBlockstore { /// expect that the CID correctly represents the data being passed. In case /// of the identity CID, nothing is written to the store. pub async fn put_keyed(&self, cid: &Cid, data: &[u8]) -> Result<(), Error> { - if is_identity(&cid).is_some() { + if get_identity_data(&cid).is_some() { return Ok(()); } @@ -494,8 +494,7 @@ mod tests { .await .unwrap(); - // Writing a new block should fail because the Blockstore is in ready - // only mode. + // Writing a new block should fail because the Blockstore is in read only mode. let payload = b"Hello World!"; let cid = Cid::new_v1(RAW_CODE, generate_multihash::(payload)); let writing_result = blockstore.put_keyed(&cid, payload).await;