io.file.flush
Flushes the stream and returns non-null on success
Return value
See iostream.stream.flush for the generic contract. Unlike a blob, a file has a real buffer to flush, so this does real work and, in principle, can fail.
Errors
Throws the stream is invalid once the file has been closed.
Notes
close flushes too, so an explicit flush before closing is only useful to make data visible to another reader of the same file while this handle stays open.
Example
from "io" import file
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_flush.tmp"
let f = file(path, "w")
f.writestring("data")
println("f.flush() =", f.flush()) // non-null: the OS buffer for this handle was flushed
f.close()
try { f.flush(); }
catch (e) { println("f.flush() after close throws:", e); } // flushing a closed file is still an invalid stream
remove(path)Output:
f.flush() = 1
f.flush() after close throws: the stream is invalidSee also
flush | Flushes the stream and returns non-null on success |
close | Closes the file if it is still open |
constructor | Two forms: (path: string, mode: string) opens the file via fopen with the given mode; (handle: userpointer, own) wraps an existing FILE* and takes ownership (closes on destruction) when own is non-null, or shares it without closing when own is null |
| file | class index |