Whether a file should be opened for reading, writing, creation and writing, or appending.
A the operating system level, this translates to the mode of a file handle (i.e., a set of open
flags and an fdopen
mode).
None of the modes represented by this datatype translate line endings (i.e. O_BINARY
on Windows).
Furthermore, they are not inherited across process creation (i.e. O_NOINHERIT
on Windows and
O_CLOEXEC
elsewhere).
Operating System Specifics:
Constructors
read : IO.FS.Mode
The file should be opened for reading.
The read/write cursor is positioned at the beginning of the file. It is an error if the file does
not exist.
-
open
flags: O_RDONLY
-
fdopen
mode: r
write : IO.FS.Mode
The file should be opened for writing.
If the file already exists, it is truncated to zero length. Otherwise, a new file is created. The
read/write cursor is positioned at the beginning of the file.
writeNew : IO.FS.Mode
A new file should be created for writing.
It is an error if the file already exists. A new file is created, with the read/write cursor
positioned at the start.
readWrite : IO.FS.Mode
The file should be opened for both reading and writing.
It is an error if the file does not already exist. The read/write cursor is positioned at the
start of the file.
-
open
flags: O_RDWR
-
fdopen
mode: r+
append : IO.FS.Mode
The file should be opened for writing.
If the file does not already exist, it is created. If the file already exists, it is opened, and
the read/write cursor is positioned at the end of the file.