2.5.11. File

TODO.

2.5.11.1. Instruction

file.close op1 [file::Close]
Operator 1:ref<file>

Closes the file op1. Further write operations will not be possible (unless reopened. Other file objects still referencing the same physical file will be able to continue writing.

file.open op1 op2 op3 [file::Open]
Operator 1:ref<file>
Operator 2:string
Operator 3:[ tuple<*> ]

Opens a file op1 for writing. op2 is the path of the file. If not absolute, it is interpreted relative to the current directory. op3 is tuple consisting of (1) the file type, either ~~Hilti::FileType::Text or ~~Hilti::FileType::Binary; (2) the file open mode, either ~~Hilti::FileMode::Create or ~~Hilti::FileMode::Append; and (3) a string giveing the output character set for writing out strings. If op3 is not given, the default is (Hilti::FileType::Text, Hilti::FileMode::Create,         Hilti::Charset::UTF8). Raises ~~IOError if there was a problem opening the file.

file.write op1 op2 [file::WriteString]
Operator 1:ref<file>
Operator 2:string

Writes op1 into the file. The output will be encoded according to the character set given to ~~file.open. If the file was opened in text mode, unprintable bytes characters will be suitably escaped and all lines will be terminated with newlines. It is guaranteed that a single execution of this instruction is atomic in the sense that all characters will be written out in one piece even if other threads are performing writes to the same file concurrently. Multiple independent write call may however be interleaved with calls from other threads.