Weave documentation
Locus

File Operations

Local SDK file/directory operations and their separate metadata/blob writes.

The SDK calls shown below operate on a named local drive. They do not start networking or automatically replicate another writer’s drive. A file write updates blob content and Lens metadata through separate operations; a journal record is not a cross-store transaction. Absolute-looking file paths are paths inside the Locus model, not host filesystem paths.

This example is checked against source signatures; it was not compiled or run during this documentation pass.

use weave_sdk::prelude::*;

#[tokio::main]
async fn main() -> WeaveResult<()> {
    // Bring up a node and open a Locus drive named "workspace".
    let node = WeaveNode::builder()
        .namespace("l1fe")
        .identifier("locus-file-ops")
        .storage_dir("/tmp/weave-locus-file-ops")
        .build()
        .await?;
    node.open_locus("workspace").await?;

    // Create, write, list, read, and remove — the round-trip every caller exercises first.
    node.locus_mkdir("workspace", "/docs").await?;
    node.locus_write_file("workspace", "/docs/README.md", b"# hello").await?;
    node.locus_write_file("workspace", "/docs/draft.txt", b"work in progress").await?;

    let entries = node.locus_readdir("workspace", "/docs").await?;
    let bytes = node.locus_read_file("workspace", "/docs/README.md").await?;
    node.locus_remove("workspace", "/docs/draft.txt").await?;
    let after = node.locus_readdir("workspace", "/docs").await?;

    println!(
        "entries_before={} README.md={} bytes entries_after={}",
        entries.len(),
        bytes.len(),
        after.len(),
    );
    Ok(())
}

Source declarations