Skip to content

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

ParameterTypeRequirementExplanation
filePathstringrequiredThe fully qualified, root-based, POSIX path to the file in the VFS
lengthnumberoptionalRead at most this many bytes starting from offset (or until EOF); if not specified or zero, a default buffer of 32 KiB is used
offsetnumberoptionalSkip this many bytes from the beginning of the file; if not specified, reads from the beginning
whencenumberoptionalOne 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");
}