Skip to content

ReadFileAsBytes()

ts
ReadFileAsBytes(filePath: string, length?: number, offset?: number, whence?: number): respReadBytes;

Reads the specified file from the VFS and returns its contents as an array of unsigned 8-bit integers (bytes) in a respReadBytes 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.ReadFileAsBytes("/images/pic.jpg", 2);
    if (resp.Ok()) {
        Log(JSON.stringify(resp.Data())); // This will log: [255,216]
    } else {
        Log("Error: " + resp.ErrorMsg());
    }
} else {
    Log("VFS was null");
}