lance_core/utils/blob.rs
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright The Lance Authors
3
4use object_store::path::Path;
5
6/// Format a blob sidecar path for a data file.
7///
8/// Layout: `<base>/<data_file_key>/<blob_id>.blob`
9/// - `base` is typically the dataset's data directory.
10/// - `data_file_key` is the stem of the data file (without extension).
11/// - `blob_id` is the hex-encoded identifier assigned during write.
12pub fn blob_path(base: &Path, data_file_key: &str, blob_id: u32) -> Path {
13 let file_name = format!("{:08x}.blob", blob_id);
14 base.child(data_file_key).child(file_name.as_str())
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20
21 #[test]
22 fn test_blob_path_formatting() {
23 let base = Path::from("base");
24 let path = blob_path(&base, "deadbeef", 2);
25 assert_eq!(path.to_string(), "base/deadbeef/00000002.blob");
26 }
27}