ReadFileAsHex()
ts
ReadFileAsHex(filePath: string, length?: number, offset?: number, whence?: number): respReadString;Reads the specified file from the VFS and returns its contents as a base-16 (hexadecimal) string in a respReadString response object.
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 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.ReadFileAsHex("/images/pic.jpg", 2);
if (resp.Ok()) {
Log(resp.Data()); // If file is JPEG, this will log: FFD8
} else {
Log("Error: " + resp.ErrorMsg());
}
} else {
Log("VFS was null");
}