io.file.eos
Returns non-null if the stream is at end-of-stream
Return value
See iostream.stream.eos for the generic contract.
Errors
Throws the stream is invalid once the file has been closed.
Notes
This is tell() == len(), so it costs the same two extra seeks as len (see its Notes) every time it is called. Seeking past the real end moves tell without moving len, so eos correctly reports false there, even though a read at that position fails.
Example
from "io" import file
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_eos.tmp"
let f = file(path, "w+")
f.writestring("ab")
println("f.eos() after write =", f.eos()) // just wrote up to the end, so the cursor is there too
f.seek(0)
println("f.eos() after seek(0) =", f.eos()) // rewound, one byte away from the end
f.close()
remove(path)Output:
f.eos() after write = 1
f.eos() after seek(0) = nullSee also
eos | Returns non-null if the stream is at end-of-stream |
tell | Returns the current stream position |
len | Returns the stream length |
close | Closes the file if it is still open |
| file | class index |