moon_storage.storage
Metadata for one stored key.
key: string | Root-relative POSIX key naming the file. |
|---|---|
name: string | Final path component of the key. |
size: int | File length in bytes. |
modified_ms: int | Last modification time in milliseconds since the Unix epoch. |
content_type: string | MIME type guessed from the extension. |
Total and available bytes for a storage filesystem.
total_bytes: int | Capacity of the filesystem holding the root. |
|---|---|
available_bytes: int | Bytes still writable on it. |
Filesystem-backed adapter rooted at one directory.
base_path: string | Absolute directory every key of this adapter resolves under. |
|---|
Ordered collection of storage roots with deterministic key placement.
adapters: [Adapter] | The roots in priority order; the first one is where writes land. |
|---|
path.resolve(value): absolute, lexically normalized.
value: Path to resolve against the current directory.
Creates the directory (recursively) and returns a rooted adapter.
base_path: Directory to root the adapter at, created along with its parents.
use moon_storage.storage
fn main() {
let files = storage.create(".moon/storage").unwrap()
files.write("notes/moon.txt", "moon\n").unwrap()
files.append("notes/moon.txt", "Tour\n").unwrap()
println(files.exists("notes/moon.txt"))
println(files.read("notes/moon.txt").unwrap())
println(files.stat_item("notes/moon.txt").unwrap().size)
println(files.list("notes").unwrap().len())
files.rename("notes/moon.txt", "notes/tour.txt").unwrap()
files.truncate("notes/tour.txt", 4).unwrap()
files.delete("notes/tour.txt").unwrap()
}Creates a multi-root adapter after validating the supplied directories.
directories: Roots in priority order; the first is the write target.
use moon_storage.storage
async fn main() {
let files = storage.create_multi(["/mnt/fast", "/mnt/archive"]).unwrap()
println(files.base_path())
println(files.base_paths())
files.write("video/moon.mp4", "bytes").unwrap()
println(files.adapter_for("video/moon.mp4").is_some())
println((await files.list("video")).unwrap())
let capacity = files.disk_space()
println(capacity.total_bytes)
println(capacity.available_bytes)
}True when candidate is root itself or lies beneath it, comparing whole path segments rather than raw string prefixes.
root: Directory that must contain the candidate.candidate: Path to test, compared segment by segment.
let root = moon_storage.storage.absolute(".moon/storage")
println(moon_storage.storage.contains_path(root, root + "/notes/moon.txt"))
println(moon_storage.storage.contains_path(root, root + "-backup/file"))
println(moon_storage.storage.disk_space_of(root).available_bytes)resolvePath: the absolute path for a key, or a validation error when the key escapes the base directory.
key: Storage key, relative to the root and never escaping it.
Reports whether the key exists in the selected storage root.
key: Storage key, relative to the root and never escaping it.
stat(key): the storage item, or none when the key does not exist.
key: Storage key, relative to the root and never escaping it.
Every file under prefix, recursively, skipping dot-directories — the same traversal list() performs.
prefix: Key prefix to walk under; empty lists the whole root.
Reads the key, returning none when it does not exist.
key: Storage key, relative to the root and never escaping it.
Replaces a key's contents and returns the bytes written.
key: Storage key, relative to the root and never escaping it.data: Bytes to write.
Appends data to a key and returns the bytes written.
key: Storage key, relative to the root and never escaping it.data: Bytes to append.
Truncates a key to the requested byte size.
key: Storage key, relative to the root and never escaping it.size: Byte length to cut the file to.
Deletes a key from storage.
key: Storage key, relative to the root and never escaping it.
Renames a key within storage.
old_key: Existing key.new_key: Key to move it to, within the same root.
Returns capacity and available bytes for the storage root.
The device id of the base path, so a multi-adapter counts one filesystem once even when several video directories live on it.
df -Pk <path> — POSIX output: Filesystem, 1024-blocks, Used, Available.
directory: Path whose filesystem is measured.
Returns the primary storage base path.
Returns all configured storage base paths.
Combined capacity, counting each filesystem once.
Union of every adapter's listing; the first adapter holding a key wins.
First-adapter-wins is carried by the merge order, not the walk order: join_all returns results in input order, so the dedup loop below sees the adapters in exactly the sequence the old serial loop did. The returned error is likewise the first in adapter order, matching the ? this replaced. What does change is failure coverage: a middle adapter's error no longer stops the later roots from being read. They run anyway and their results are dropped. Listing is read-only, so that is wasted work on the error path and nothing more.
It remains true that the fix that works best is upstream, in not calling this: a caller that knows which keys changed patches those entries (stat_item) instead of asking for the whole namespace again.
prefix: Key prefix to walk under in every root.
Returns the storage adapter selected for a key.
key: Storage key to place; the first root holding it wins.
Reports whether the key exists in the selected storage root.
key: Storage key, relative to the root and never escaping it.
Returns metadata for a stored key when present.
key: Storage key, relative to the root and never escaping it.
The absolute path of a key, wherever it lives.
key: Storage key, relative to the root and never escaping it.
Reads the key, returning none when it does not exist.
key: Storage key, relative to the root and never escaping it.
Writes always land in the first directory.
key: Storage key, relative to the root and never escaping it.data: Bytes to write.
Appends data to a key and returns the bytes written.
key: Storage key, relative to the root and never escaping it.data: Bytes to append.
Truncates a key to the requested byte size.
key: Storage key, relative to the root and never escaping it.size: Byte length to cut the file to.
Deletes a key from storage.
key: Storage key, relative to the root and never escaping it.
Renames a key within storage.
old_key: Existing key.new_key: Key to move it to.
The write target for a new key: the first directory.