Lets make it similar to what Rust provide in the OpenOptions types, i.e.
read, allow reading, not sure if we should be make this always present, does it make sense to open file for writing only?
write, allow writing.
create, if file is not found, create new
create_new, fail if file is available
append, "implicit write", start from end of file
truncate, if the file is available, set it to 0 size.
All of the flags may be used with each other, i.e. I don't think we need to report hard error if for example "create + create_new", but instead will need to ignore other fields.
The operation will be something like this.
write = write or append # append implicit "write"
file = open(read, write)
if not file:
if create or create_new:
return create(read, write)
fail "File not available"
else:
if create_new:
fail "already exist"
# here, the file is opened
if truncate:
if write:
file.set_length(0)
else:
fail "File is not writable, can't truncate"
if append:
file.seek(END, 0)
Lets make it similar to what Rust provide in the
OpenOptions
types, i.e.All of the flags may be used with each other, i.e. I don't think we need to report hard error if for example "create + create_new", but instead will need to ignore other fields.
The operation will be something like this.