Quirrel4.41.0

io.file.eos

Method of file, from module "io"

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

examples/io/file/eos.nut
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) = null

See also

eosReturns non-null if the stream is at end-of-stream
tellReturns the current stream position
lenReturns the stream length
closeCloses the file if it is still open
fileclass index