io.ReadAll
The Go function that reads an io.Reader until the end and returns everything as one slice of bytes.
In more detail
It holds the whole stream in memory, which is fine for small trusted input and dangerous for anything unbounded. Wrap untrusted sources in io.LimitReader first.
Example
data, err := io.ReadAll(reader)Related terms
- io.LimitReader — The Go function that wraps an io.Reader so it stops after a set number of bytes, capping how much you will read.
- untrusted input — Any data a program did not create itself, including arguments, form fields, request bodies, file contents, file names and environment variables.
- io.Reader — The Go interface for anything you can read bytes from, such as a file, a network connection or an HTTP response body.
Taught in
- Streams and the io Package — Concurrent Systems Programming with Go