File systemReferenceNew · 0.744
writefileasync
Create or replace a local file asynchronously.
Details#
Writes the supplied bytes to a workspace file, creating it if needed. An existing file is truncated before writing; this is a replacement operation, not an append. Parent directories are not created automatically. A failed write can leave a changed or incomplete file, so success must be checked before using it.
Signature#
writefileasync(path: string, data: string): (boolean?, string?)Parameters#
| Parameter | Type | Description |
|---|---|---|
path | string | A file path inside your workspace. The parent directory must already exist for writes. |
data | string | The bytes to write; binary strings are supported. |
Returns#
On success, true. On an I/O failure, nil and an error string. Invalid arguments or paths raise an error.
Examples#
Local example
local ok, err = writefileasync("notes.txt", "Local note\n")
if not ok then
warn(err)
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.