Crates.io | list_with_depth |
lib.rs | list_with_depth |
version | |
source | src |
created_at | 2024-12-09 11:18:39.863732 |
updated_at | 2024-12-09 17:13:44.397299 |
description | List objects from object_store with the given prefix and depth. |
homepage | https://github.com/JackKelly/list_with_depth |
repository | https://github.com/JackKelly/list_with_depth |
max_upload_size | |
id | 1477244 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
List objects from [object_store
] with the given prefix and depth,
and an implementation specific delimiter.
Returns common prefixes (directories) in addition to object metadata.
For example, say that a bucket contains the following objects:
a.txt
foo/b.txt
foo/bar/c.txt
foo/bar/d.txt
Calling [list_with_depth
] with depth = 0
is equivalent to calling
[ObjectStore::list_with_delimiter
]: It will return the objects and common
prefixes at the root: objects=["a.txt"]
and common_prefixes=["foo"]
.
Calling [list_with_depth
] with depth = 1
will recurse once, and return
objects=["foo/b.txt"]
and common_prefixes=["foo/bar"]
.
The equivalent commands at a Unix command line would be:
ls *
(depth=0)ls */*
(depth=1)ls */*/*
(depth=2)Prefixes are evaluated on a path segment basis, i.e. foo/bar
is a
prefix of foo/bar/x
but not of foo/bar_baz/x
.
use std::sync::Arc;
use list_with_depth::list_with_depth;
use object_store::{memory::InMemory, PutPayload, ObjectStore, ListResult, path::Path};
#[tokio::main(flavor = "current_thread")]
async fn main() -> object_store::Result<()> {
// Create some objects in memory:
const KEYS: [&str; 4] = [
"a.txt",
"foo/b.txt",
"foo/bar/c.txt",
"foo/bar/d.txt",
];
let store = Arc::new(InMemory::new());
for key in KEYS {
store.put(&key.into(), PutPayload::new()).await?;
}
// Call `list_with_depth` with `depth = 0`:
let depth = 0;
let prefix = None;
let ListResult{
objects,
common_prefixes
} = list_with_depth(store.clone(), prefix, depth).await?;
assert_eq!(objects[0].location, Path::from("a.txt"));
assert_eq!(common_prefixes, vec![Path::from("foo")]);
// Call `list_with_depth` with `depth = 1`:
let depth = 1;
let prefix = None;
let ListResult{
objects,
common_prefixes
} = list_with_depth(store.clone(), prefix, depth).await?;
assert_eq!(objects[0].location, Path::from("foo/b.txt"));
assert_eq!(common_prefixes, vec![Path::from("foo/bar")]);
Ok(())
}