Quirrel4.41.0

iostream.stream.len

Method of stream, from module "iostream"
instance.len(): int

Returns the stream length

Return value

The number of bytes the stream currently holds. This does not depend on the cursor; use tell for that.

Notes

The same method works on a file, where it reports the file's size: writing past the current length grows the stream to fit, on a blob and on a writable file alike.

Example

examples/iostream/stream/len.nut
from "iostream" import blob

let b = blob(3)
println("b.len() at start =", b.len())
b.seek(0, 'e')
b.writen(1, 'l') // writes 8 bytes past the current len of 3, growing it
println("b.len() after writen =", b.len())
b.seek(0)
println("b.len() after seek(0) =", b.len())  // seeking never changes len
println("b.tell() after seek(0) =", b.tell()) // len and tell are independent
Output:
b.len() at start = 3
b.len() after writen = 11
b.len() after seek(0) = 11
b.tell() after seek(0) = 0

See also

lenReturns the stream length
tellReturns the current stream position
writenWrites a numeric value in the given format
streamclass index