File:mode
methodFile:mode() -> app.PreopenModeThe file's access mode.
handle7 methods, 1 field
A capability for one file inside a granted directory. Read, write, stat, or load it as a Lua module / package.
Dir:open, datumhue.argsdatumhue.app.spawnThe examples on this page start from:
local notes = datumhue.args.dirs.notes
notes:create_file("todo.txt"):ready()
local file = notes:open("todo.txt")| Field | Type | Access | Description |
|---|---|---|---|
name | string | read-only | The file's name. A file opened from a directory is named by the directory's name, a slash and its path inside the directory (notes/log.txt). |
File:mode() -> app.PreopenModeThe file's access mode.
File:read() -> BytesReturn a file-backed Bytes handle for this file at once; the file is read when a decoder method runs. Decode via file:read():text(), file:read():image(), file:read():parquet(), etc.
In the guide: Open, pick and save files
Overwrite the file with bytes. Requires rw mode. A string is not accepted; wrap it with datumhue.bytes first. The write starts immediately; file:write(b):ready() observes completion or failure.
file:write(datumhue.bytes("milk, eggs")):ready()
print(file:read():text()) --> milk, eggsFile:stat() -> StatMetadata for this file — the same fields dir:stat returns.
In the guide: Open, pick and save files
File:require() -> anyLoad this file as a Lua module and run it once; repeat calls on the same handle hand back the same value. Each file handle's require is independent. A compiled chunk loads only from the Lua files of a sealed package; anywhere else it raises.
local source = [[
return function(name)
return "Hello, " .. name
end
]]
notes:write("greet.lua", datumhue.bytes(source)):ready()
local greet = notes:open("greet.lua"):require()
print(greet("Ada")) --> Hello, AdaIn the guide: Modules and dependencies The Lua sandbox
File:book() -> BookLoad this .kdl page as a one-chapter book. Raises with file:line:col diagnostics on parse or validation errors.
local page = [[
page title="Welcome" {
label "Hello"
}
]]
notes:write("welcome.kdl", datumhue.bytes(page)):ready()
local welcome = notes:open("welcome.kdl"):book()
print(welcome.title) --> WelcomeIn the guide: Write a book
File:load_package() -> PackageRead this file's bytes and parse them as a .dhpkg archive, returning a typed Package handle.
local archive = datumhue.args.files.tools
local tools = archive:load_package()
print(tools.name, tools:version())In the guide: Packages and identity