Standard library / io

io.ReadAll()

Reads until EOF or error and returns accumulated bytes. Bound untrusted input before using it to avoid excessive memory use. Expected stdout: 'abc <nil>\n'.

Formal Syntax & Structure

go syntaxgo
func ReadAll(r Reader) ([]byte, error)

Parameters & Attributes

NameTypeDescription
rReaderSource reader.

Return Value

([]byte, error)

Reads until EOF or error and returns accumulated bytes.

Working Example

Example Snippetgo
package main
import (  "fmt"  "io"  "strings")
func main() { b, e := io.ReadAll(strings.NewReader("abc")); fmt.Println(string(b), e) }
Go Reference