The io Reader interface

The io.Reader interface defines a standard Read method for streaming data from any source in Go.

The io.Reader interface is a standard Go interface that defines a single method, Read, used to read data from a source sequentially. It is implemented by types like *tar.Reader to allow streaming access to tar archive contents without loading the entire file into memory.

import "io"

type Reader interface {
    Read(p []byte) (n int, err error)
}

The Read method copies data from the source into the provided byte slice p, returning the number of bytes read and any error encountered, such as io.EOF when the stream ends.