File systemReferenceNew · 0.744
readfileasync
Read a local file asynchronously.
Details#
Reads the full contents of an existing workspace file. The returned string preserves the file's bytes, including zero bytes. The call waits by yielding and returns when reading is complete. A missing or unreadable file returns nil and an error message.
Signature#
readfileasync(path: string): (string?, string?)Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | A file path inside your workspace. The parent directory must already exist for writes. |
Returns#
On success, one string containing the file bytes. On an I/O failure, nil and an error string. Invalid arguments or paths raise an error.
Examples#
Local example
local data, err = readfileasync("notes.txt")
if data == nil then
warn(err)
else
print(data)
endNotes#
- The call yields until the operation finishes, then returns its result. It does not return a promise or take a callback.
- Invalid argument types and rejected paths raise an error. A file I/O failure instead returns nil and an error string; check both results.
- Files larger than 2,147,483,647 bytes are rejected. The complete file is returned in memory; use modest file sizes.