Skip to content

WriteFileAsHex()

ts
WriteFileAsHex(filePath: string, data: string, offset: number, whence: number): respBase;

Writes the provided base-16 (hexadecimal) encoded data to the filePath file in the VFS, starting at the specified offset computed from whence. The file is treated as binary data.

Parameters

ParameterTypeExplanation
filePathstringThe fully qualified, root-based, POSIX path to the file in the VFS
datastringThe string of hex-encoded bytes to write to the file
offsetnumberThe positional offset, computed from whence, where the write operation will begin
whencenumberOne 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.WriteFileAsHex("/data/archive.dat", "FFD8", 0, FromEnd);
    if (resp.Ok()) {
        Log("Data written"); // Bytes 255 (FF) and 216 (D8) appended to file
    } else {
        Log("Error: " + resp.ErrorMsg());
    }
} else {
    Log("VFS was null");
}