Skip to content
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#

Luau
readfileasync(path: string): (string?, string?)

Parameters#

ParameterTypeDescription
pathstringA 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

Luau
local data, err = readfileasync("notes.txt")
if data == nil then
    warn(err)
else
    print(data)
end

Notes#

  • 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.