zephyr.io

Sandboxed file storage. Paths are virtual, rooted at the module's persistent data directory (`ZEPHYR_DATA_DIR/modules/<module_id>`); absolute-looking paths are still scoped there and parent traversal is rejected. Reads and writes use raw Lua-string bytes. All functions require the `io` permission.

7 functions

write

io
zephyr.io.write(path, data)

Write raw bytes to a file, creating or replacing it.

Parameters

pathstring

Virtual module path.

datastring

Raw bytes to write.

Returns

nil

Nothing.

Raises an error if

  • the io permission is not granted

Example

lua
zephyr.io.write("/cache/song.mp3", bytes)

read

io
zephyr.io.read(path)

Read a file's contents as raw bytes.

Parameters

pathstring

Virtual module path.

Returns

string

The file contents as a raw byte string.

Raises an error if

  • the io permission is not granted

exists

io
zephyr.io.exists(path)

Check whether a path exists.

Parameters

pathstring

Virtual module path.

Returns

boolean

true if the path exists.

Raises an error if

  • the io permission is not granted

delete

io
zephyr.io.delete(path)

Delete a file or directory.

Parameters

pathstring

Virtual module path.

Returns

nil

Nothing.

Raises an error if

  • the io permission is not granted

mkdir

io
zephyr.io.mkdir(path)

Create a directory (and any missing parents).

Parameters

pathstring

Virtual module path.

Returns

nil

Nothing.

Raises an error if

  • the io permission is not granted

Example

lua
zephyr.io.mkdir("/cache")

metadata

io
zephyr.io.metadata(path)

Return metadata about a path.

Parameters

pathstring

Virtual module path.

Returns

table

Metadata with path, kind (file/directory/other), and size (bytes, or nil for directories).

Raises an error if

  • the io permission is not granted

list

io
zephyr.io.list(path?)

List directory entries.

Parameters

pathstringoptional

Virtual module path. Defaults to the module root.

Returns

table[]

Entries with name, path, kind, and size.

Raises an error if

  • the io permission is not granted