Standard library / bytes

bytes.Reader.Read()

Copies up to len(b) bytes from the cursor; returns count and error, including EOF when exhausted. Process n bytes before handling error. Expected stdout: '1 <nil> a\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) Read(b []byte) (n int, err error)

Parameters & Attributes

NameTypeDescription
b[]byteWritable destination slice; its length limits bytes read.

Return Value

(n int, err error)

Copies up to len(b) bytes from the cursor; returns count and error, including EOF when exhausted. Process n bytes before handling error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt")
func main() {  r := bytes.NewReader([]byte("aé"))  b := make([]byte, 1)  n, e := r.Read(b)  fmt.Println(n, e, string(b[:n]))}
Go Reference