writefile / appendfile / writefileasync / appendfileasync
Writes or appends workspace files; the async variants yield instead of blocking.
Syntax
writefile(path: string, data: string) -> ()
appendfile(path: string, data: string) -> ()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | string | Workspace-relative path. |
data | string | Contents to write. |
Returns
| Type | Description |
|---|---|
() | No return values. |
Description
writefile replaces the file, appendfile adds to the end. Both enforce the workspace sandbox and blocked extensions.
Logic change: writefileasync and appendfileasync are implemented with task.defer plus a yield/resume round-trip. They return while the write continues in the background and re-raise write errors in the caller.
Example
writefileasync("log.txt", "line 1")
appendfileasync("log.txt", "line 2")
print(readfile("log.txt"))