io.file.tell
Returns the current stream position
from "io" import file
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_tell_basic.tmp"
let f = file(path, "w+")
f.writestring("ammo")
println("f.tell() =", f.tell())
f.close()
remove(path)Output:
f.tell() = 4Return value
See iostream.stream.tell for the generic contract.
Errors
Throws the stream is invalid once the file has been closed.
Notes
What a fresh handle in mode a reports before the first write is up to the C runtime: 0 on Windows, the end of the file on Linux. The write lands at the real end either way, and after it tell reports the true position.
This is the same cursor that seek, readn, writen, readblob and writeblob move.
Example
from "io" import file
from "system" import getenv, remove
let path = $"{getenv("TEMP") ?? getenv("TMP") ?? "/tmp"}/qrl_io_file_tell.tmp"
let w = file(path, "w")
w.writestring("abcde")
w.close()
let a = file(path, "a")
a.writestring("Z")
println("a.tell() after an append =", a.tell()) // the write landed at the real end
a.seek(2)
println("a.tell() after seek(2) =", a.tell())
a.close()
remove(path)Output:
a.tell() after an append = 6
a.tell() after seek(2) = 2See also
tell | Returns the current stream position |
seek | Seeks to the given offset; origin is 'b' (begin), 'c' (current) or 'e' (end) |
len | Returns the stream length |
| file | class index |