Moves by pos bytes relative to .START, .CURRENT or .END of the file. A negative pos goes backwards. Returns
false for a closed file or when the result would be before the start. Going past the end is allowed.
file_seek :: (file: File, pos: s64, type: Seek_Type) -> success: bool
Parameters
- file: File
- pos: s64
- type: Seek_Type
Returns
- success: bool
#import "Extensions/Environment";
base := environment_variable("TMPDIR");
if base == "" base = environment_variable("TEMP");
if base == "" base = "/tmp";
path := tprint("%/jai-doc-file-seek.bin", base);
defer file_delete(path);
assert(write_entire_file(path, "abcdef"));
file, ok := file_open(path);
assert(ok);
defer file_close(*file);
assert(file_seek(file, -2, .END));
tail, tail_ok := read_entire_file(file);
assert(tail_ok && tail == "ef");
free(tail);
assert(file_seek(file, 1, .START) && file_seek(file, 2, .CURRENT));
position, position_ok := file_current_position(file);
assert(position_ok && position == 3);
assert(!file_seek(file, -1, .START));Doesn't run in the browser (only on windows).