ReadFileAsText()
ts
ReadFileAsText(filePath: string, length?: number, offset?: number, whence?: number): respReadString;Reads the specified file as plain text from the VFS and returns it in a respReadString response object.
WARNING
If the file is not a plain-text file, the Data() method of the resulting object will contain unusable data. Use this method with caution.
Parameters
| Parameter | Type | Requirement | Explanation |
|---|---|---|---|
filePath | string | required | The fully qualified, root-based, POSIX path to the file in the VFS |
length | number | optional | Read at most this many bytes (plain-text characters) starting from offset (or until EOF); if not specified or zero, a default buffer of 32 KiB is used |
offset | number | optional | Skip this many bytes from the beginning of the file; if not specified, reads from the beginning |
whence | number | optional | One of: FromStart, FromEnd; if not specified, reads from the beginning |
Example
ts
var vfs = GetCurrentVFS();
if (vfs != null) {
var resp = vfs.ReadFileAsText("/data/welcome.txt", 1024, 6, FromStart);
if (resp.Ok()) {
Log(resp.Data()); // Will log: World!
} else {
Log("Error: " + resp.ErrorMsg());
}
} else {
Log("VFS was null");
}