Qu

read_all

Builtin index · File I/O

result = read_all(f)

Input: f · Output: result

What it is

Reads every remaining byte from f (file handle, opened readable).

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = read_all(f)
f stringnot documented yet
result string
Returns the remaining content as one string — possibly the empty string "" if called right at EOF, which is a legitimate result here, not the Nothing sentinel every other read in this section returns.

Examples

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

write("a", 1, "b")
print("")
f = fopen("scratch_write_demo.txt", "w")
write(f, "hello file")
close(f)
g = fopen("scratch_write_demo.txt", "r")
print(read_all(g))
close(g)
output
a 1 b
hello file

from repl-diagnostics

f = fopen("log.txt", "r")
for i = 0 to 1
    print(read_line(f))
end for
close(f)

g = fopen("log.txt", "r")
print(read_all(g))
close(g)
output
run started
value = 42
run started
value = 42

from file-io

path = "touch_target.txt"
had_before = file_exists(path)
touch(path)
exists_after_touch = file_exists(path)

f = fopen(path, "w")
write_line(f, "original content")
close(f)

touch(path)                 # existing file: content must survive untouched


g = fopen(path, "r")
content = read_all(g)
close(g)

print("had_before = {had_before}")
print("exists_after_touch = {exists_after_touch}")
print("content = {content}")

from tour

f = fopen("greeting.txt", "w")
write_char(f, "Hello,World")
close(f)

g = fopen("greeting.txt", "r")
first       = read_char(g)         # "H"

peeked      = peek_char(g)         # "e" -- cursor not moved

next        = read_char(g)         # "e" again, same char peeked returned

chunk       = read_chars(g, 3)     # "llo"

next_byte   = peek_byte(g)         # 44, the byte for ',' -- still not consumed

before_comma = read_until(g, ",")  # "" -- the comma was right there, now consumed

w_byte      = read_byte(g)         # 87, the byte for 'W'

rest        = read_all(g)          # "orld"

close(g)
print("{first}{next}{chunk} peeked={peeked} next_byte={next_byte} before_comma=\"{before_comma}\" w_byte={w_byte} rest={rest}")
# Hello peeked=e next_byte=44 before_comma="" w_byte=87 rest=orld

output
Hello peeked=e next_byte=44 before_comma="" w_byte=87 rest=orld

from file-io

How it works

read_all(f) — the remaining content (possibly empty at EOF — an empty read is a legitimate, non-exceptional result here, unlike the "is there anything at all" question read_line/ read_char/read_byte/read_bit answer). For a "r" (text) handle: one Value::Str, same as always. For an "rb" (binary) handle: a Value::Vec of raw bytes (0-255), same representation read_bin uses — see the bug note below. § position-control + typed-binary-I/O pass (2026-08-26): this used to run EVERY remaining byte through String::from_utf8_lossy regardless of st.binary, silently replacing any byte sequence that wasn't valid UTF-8 with U+FFFD replacement characters — real, silent data corruption for exactly the "open a binary file, read it all" case this pass was asked to check. Fixed here: binary-mode read_all now returns the exact bytes, never decoded as text; text-mode read_all is UNCHANGED (still Value::Str), so every existing script/test that opens "r"/"w" text handles sees no behavior difference. read_all(f) on a Value::UrlStream (from StreamURL) — see net_ops::stream_read_all's own doc comment. Always Value::Str (no binary-mode StreamURL), matching http_get's own "HTTP bodies are text" convention.

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