io.EOF
The sentinel error an io.Reader returns when there is no more data to read, meaning the stream ended normally.
In more detail
EOF stands for end of file. Loops that read a stream stop when they see io.EOF and treat it as success, not failure. Helpers such as io.ReadAll and io.Copy handle it for you and return a nil error at the end.
Example
if errors.Is(err, io.EOF) { break }Related terms
- io.Reader — The Go interface for anything you can read bytes from, such as a file, a network connection or an HTTP response body.
- sentinel error — A specific error value published in a package-level variable, such as io.EOF or os.ErrNotExist, that callers can test for with errors.Is.
- io.ReadFull — The Go function that reads exactly as many bytes as a buffer holds, returning an error if the stream ends first.
Taught in
- Streams and the io Package — Concurrent Systems Programming with Go