Skip to content

WriteFileAsBytes()

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

Writes the provided array of bytes (data) to the specified file in the VFS, starting at the given offset computed from whence. The file is treated as binary data.

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.

Parameters

ParameterTypeExplanation
filePathstringThe fully qualified, root-based, POSIX path to the file in the VFS
dataUint8ArrayThe byte-array (array of unsigned 8-bit integers) to write to the file
offsetnumberThe positional offset, computed from whence, where the write operation will begin
whencenumberOne of: FromStart, FromEnd

Example

ts
var vfs = GetCurrentVFS();
if (vfs != null) {
    var resp = vfs.WriteFileAsBytes("/data/archive.dat", [255,216], 0, FromEnd);
    if (resp.Ok()) {
        Log("Data written"); // Bytes 255 and 216 appended to file
    } else {
        Log("Error: " + resp.ErrorMsg());
    }
} else {
    Log("VFS was null");
}