Skip to main content

void_core/metadata/
bundle.rs

1//! MetadataBundle implementation.
2
3use super::{hash_dir_path_u64, hash_path_u64, MetadataBundle, ShardMap, ShardRange};
4use void_crypto::RepoSecret;
5
6impl MetadataBundle {
7    pub const VERSION: u32 = 1;
8    pub const DEFAULT_RANGE_COUNT: u64 = 64;
9
10    /// Creates a new metadata bundle with the given repo secret and shard map.
11    pub fn new(repo_secret: RepoSecret, shard_map: ShardMap) -> Self {
12        Self {
13            version: Self::VERSION,
14            repo_secret,
15            shard_map,
16        }
17    }
18
19    /// Convenience constructor for a new map with the default range count.
20    pub fn with_default_map(repo_secret: RepoSecret) -> Self {
21        Self::new(repo_secret, ShardMap::new(Self::DEFAULT_RANGE_COUNT))
22    }
23
24    /// Returns the shard range for a given file path.
25    pub fn range_for_path(&self, path: &str) -> Option<&ShardRange> {
26        self.shard_map
27            .range_for_hash(hash_path_u64(&self.repo_secret, path))
28    }
29
30    /// Returns the shard range for a given directory path.
31    pub fn range_for_dir(&self, dir_path: &str) -> Option<&ShardRange> {
32        self.shard_map
33            .range_for_hash(hash_dir_path_u64(&self.repo_secret, dir_path))
34    }
35}