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
| Parameter | Type | Explanation |
|---|---|---|
filePath | string | The fully qualified, root-based, POSIX path to the file in the VFS |
data | Uint8Array | The byte-array (array of unsigned 8-bit integers) to write to the file |
offset | number | The positional offset, computed from whence, where the write operation will begin |
whence | number | One 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");
}