WriteFileAsText()
ts
WriteFileAsText(filePath: string, data: string, offset: number, whence: number): respBase;Writes the provided plain-text data to the filePath file in the VFS, starting at the specified offset computed from whence. The file is written as plain text.
Parameters
| Parameter | Type | Explanation |
|---|---|---|
filePath | string | The fully qualified, root-based, POSIX path to the file in the VFS |
data | string | The string of plain-text to write to the file |
offset | number | The positional offset, computed from whence, where the write operation will begin |
whence | number | One of: FromStart, FromEnd |
NOTE
offset and whence together determine where writing begins. 0,FromStart overwrites the file from the beginning; 0,FromEnd appends new data to the file.
Example
ts
var vfs = GetCurrentVFS();
if (vfs != null) {
var resp = vfs.WriteFileAsText("/data/hello.txt", " World!", 0, FromEnd);
if (resp.Ok()) {
Log("Data written to file"); // File now contains: Hello World!
} else {
Log("Error: " + resp.ErrorMsg());
}
} else {
Log("VFS was null");
}