Qu

StreamFile

Builtin index · File I/O

result = StreamFile(path, [mode])

Input: path, mode · Output: result

What it is

A second name for exactly fopen's own machinery. path (string, filesystem path) is the file to open. mode (string, optional, default "r") accepts the same mode strings fopen does.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = StreamFile(path, [mode])
path stringpath (string, filesystem path) is the file to open.
mode string, optionalmode (string, optional, default "r") accepts the same mode strings fopen does.
result —
Returns a Value::File handle — the same concrete type fopen returns — so every existing real-streaming fopen builtin (read_line, read_all, seek, eof, read_bin, ...) already works on it, not just the four listed here.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

n = fopen("notes.txt", "w")
write_line(n, "line one")
write_line(n, "line two")
close(n)

function drain(s)
    total = ""
    while not eof(s)
        total = total + read_line(s) + "|"
    end while
    close(s)
    return total
end function

a = drain(StreamFile("notes.txt"))
print(a)                                    # line one|line two|


b = drain(StreamURL("https://example.com/"))
print(length(b) > 0)                        # true -- some HTML came back

output
line one|line two|
true

from file-io

function drain(s)
    total = ""
    while not eof(s)
        total = total + read_line(s) + "|"
    end while
    close(s)
    return total
end function

# Written here so the file half runs; the URL half cannot be, since a

# documentation build must not depend on the network being up or on a

# third party's page not changing under it.

w = fopen("stream_notes.txt", "w")
write_line(w, "one")
write_line(w, "two")
close(w)

a = drain(StreamFile("stream_notes.txt"))
b = drain(StreamURL("https://example.com/"))
print("a = {a}")
print("b length = {length(b)}")

from tour

How it works

StreamFile(path, [mode]) (§ StreamFile/StreamURL polymorphic streams, 2026-08-31) — a second name for exactly fopen's own machinery (open_file_handle, shared verbatim, not reimplemented), so a StreamFile handle IS a Value::File and already has every one of fopen's real streaming read_line/read_all/seek/eof/close builtins for free. Exists as a distinct constructor name (rather than telling scripts to just call fopen) so "I asked for a stream" reads clearly at the call site and pairs visibly with StreamURL below — genuine polymorphism between the two comes from both producing values that respond to the same method names, not from a shared concrete type.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.