FILE I/O

ReadFile

Reads a file and returns its contents.

Syntax

local data = ONYX.ReadFile(name)

Parameters

  • name (string) — Plain file name ending in .json - no directories, no path separators.

Return(s)

string — full contents (binary-safe); nil when the file is missing or cannot be opened.

Behavior

  • Validates the name first: only plain file names matching the .json pattern are accepted; traversal attempts raise a Lua error.
  • Reads the whole file in binary mode, suitable for JSON blobs or small persistent data.
  • Not intended for large files: the entire file is loaded into memory.

Example(s)

local raw = ONYX.ReadFile("settings.json")
if raw then print(#raw) else print("no settings yet") end