Iterating a file object yields one line at a time, which is the difference between a constant footprint and an OOM.
Tag
Snippets tagged files
pathlib keeps the paths as objects rather than strings, so joining and suffix checks stay readable.
os.ReadFile replaced ioutil.ReadFile in 1.16 and is the one-liner for small files.
The stream closes itself when it leaves scope, whether the function returns normally or throws.