Standard library / bufio

bufio.Reader.Read()

Reads into caller storage; may return fewer bytes than requested and a subsequent call may return EOF. Expected stdout: '2 ab <nil>\n'.

Formal Syntax & Structure

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

Parameters & Attributes

NameTypeDescription
p[]byteByte slice supplied by the caller.

Return Value

(n int, err error)

Reads into caller storage; may return fewer bytes than requested and a subsequent call may return EOF.

Working Example

Example Snippetgo
package main
import (  "bufio"  "fmt"  "strings")
func main() {  r := bufio.NewReader(strings.NewReader("ab"))  p := make([]byte, 4)  n, e := r.Read(p)  fmt.Println(n, string(p[:n]), e)}
Go Reference