Skip to main content

object_path

Function object_path 

Source
pub fn object_path(checksum: &str) -> String
Expand description

Returns the relative, sharded path of a content object given its hex checksum.

The layout is .objects/<h[0..3]>/<h[3..6]>/<h[6..9]>/<h[9..]>, matching the oracle’s _snapdir_get_object_rel_path. The returned path always uses forward slashes (the on-disk separator the oracle emits); a store targeting a native filesystem can feed it straight to Path, and an object-store backend uses it verbatim as a key.

The checksum is used as-is; callers are expected to pass a lowercase hex digest as produced by the crate::merkle hashers. Inputs shorter than nine characters degrade gracefully (the missing shard segments and/or the trailing component are simply empty), but that is never a valid snapdir checksum.

§Examples

use snapdir_core::store::object_path;

let h = "49dc870df1de7fd60794cebce449f5ccdae575affaa67a24b62acb03e039db92";
assert_eq!(
    object_path(h),
    ".objects/49d/c87/0df/1de7fd60794cebce449f5ccdae575affaa67a24b62acb03e039db92"
);