use std::path::Path;
pub const ZARR_EXTENSION: &str = ".zarr";
#[must_use]
pub fn is_zarr_store_root_path(p: &str) -> bool {
let t = p.trim_end_matches(['/', '\\']);
t.ends_with(ZARR_EXTENSION)
}
#[must_use]
pub fn filter_zarr_input_paths(paths: impl IntoIterator<Item = String>) -> Vec<String> {
paths
.into_iter()
.filter(|p| {
if !p.contains(ZARR_EXTENSION) {
return true;
}
is_zarr_store_root_path(p)
})
.collect()
}
pub fn total_file_bytes_under(root: &Path) -> std::io::Result<usize> {
fn walk(path: &Path, acc: &mut usize) -> std::io::Result<()> {
for e in std::fs::read_dir(path)? {
let e = e?;
let p = e.path();
let md = e.metadata()?;
if md.is_dir() {
walk(&p, acc)?;
} else if md.is_file() {
*acc = acc.saturating_add(md.len() as usize);
}
}
Ok(())
}
let mut n = 0usize;
walk(root, &mut n)?;
Ok(n)
}