A directory capability. Obtained from datumhue.args.dirs[name], datumhue.package:dir(), an open_button pick, or dir:subdir(rel). Relative paths must stay inside the directory — .., absolute paths, and symlinks that escape the root are all rejected.
Return a file-backed Bytes handle for the file at rel under the directory, at once; the file is read when a decoder method runs, or when the handle is awaited.
Example
dir:write("scores.json", datumhue.bytes.json({ best = 42 })):ready()
-- Nothing is read until a decoder runs.local scores = dir:read("scores.json"):json()
print(scores.best) --> 42
Overwrite rel with bytes. Requires rw mode. A string is not accepted; wrap it with datumhue.bytes first. The write starts immediately; :ready() observes completion or failure.
Example
-- Wrap text in bytes; a plain string is not accepted.
dir:write("hello.txt", datumhue.bytes("Hello")):ready()
dir:write("save.json", datumhue.bytes.json({ level = 3 })):ready()
print(dir:read("hello.txt"):text()) --> Hello
Load the Lua module at exactly rel under the directory and run it once; repeat calls with the same rel hand back the same value. Returns the module's first return value, or true if it returned nothing. A compiled chunk loads only from the Lua files of a sealed package; anywhere else it raises.
Example
dir:write("util.lua", datumhue.bytes("return { answer = 42 }")):ready()
local util = dir:require("util.lua")
print(util.answer) --> 42-- A second require hands back the same value.print(dir:require("util.lua") == util) --> true
Load the package at rel under this directory: a regular file loads as a package archive, and a directory as a package folder, which must follow the package layout.
Example
local manifest = [[name "@me/tools"version "1.2.0"api_version "*"kind "library"]]
dir:mkdir("tools"):ready()
dir:write("tools/package.kdl", datumhue.bytes(manifest)):ready()
local tools = dir:load_package("tools")
print(tools.name, tools:version()) --> @me/tools 1.2.0
Load the book rooted at this directory: book.kdl names the title and chapters, each a page file inside the directory. Raises with file:line:col diagnostics on parse or validation errors.
Example
local contents = [[title "Field notes"chapter "Birds" file="birds.md"]]
dir:write("book.kdl", datumhue.bytes(contents)):ready()
dir:write("birds.md", datumhue.bytes("# Birds\n\nA robin.\n")):ready()
local book = dir:book()
print(book.pages, book.title) --> 1 Field notes