io package
Go's standard library package of small interfaces and helpers for moving streams of bytes, centred on io.Reader and io.Writer.
In more detail
Files, network connections, HTTP bodies and in-memory buffers all satisfy these interfaces, so one function can work with any of them. Helpers such as io.Copy, io.ReadAll, io.LimitReader and io.ReadFull build on them.
Example
import "io"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.Writer — The Go interface for anything you can write bytes to, such as a file, standard output, a buffer or an HTTP response.
- io.Copy — The Go function that streams all the bytes from an io.Reader to an io.Writer and returns how many it copied.
- 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.
Taught in
- Streams and the io Package — Concurrent Systems Programming with Go
- Calling APIs with net/http Client — Concurrent Systems Programming with Go
- Shipping in Scratch and Distroless Images — Concurrent Systems Programming with Go