Standard library / io

io.Reader

Basic streaming interface. Process p[:n] before handling err; a read can deliver bytes and an error together. Do not retain p. Expected stdout: 'ab <nil>\n'.

Formal Syntax & Structure

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

Working Example

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