Quirrel4.41.0

io.file.tell

Method of file, from module "io"
instance.tell(): int

Returns the current stream position

examples/io/file/tell-basic.nut
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() = 4

Return 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

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

See also

tellReturns the current stream position
seekSeeks to the given offset; origin is 'b' (begin), 'c' (current) or 'e' (end)
lenReturns the stream length
fileclass index