io.ReadFull
The Go function that reads exactly as many bytes as a buffer holds, returning an error if the stream ends first.
In more detail
Use it when a format requires a fixed-size piece, such as a header of known length. A short read becomes an explicit error (io.ErrUnexpectedEOF) instead of silently partial data.
Example
buf := make([]byte, 4)
_, err := io.ReadFull(r, buf)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.
- io.ReadAll — The Go function that reads an io.Reader until the end and returns everything as one slice of bytes.
Taught in
- Streams and the io Package — Concurrent Systems Programming with Go