Source file tour/methods/reader.go

     1  //go:build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"io"
     8  	"strings"
     9  )
    10  
    11  func main() {
    12  	r := strings.NewReader("Hello, Reader!")
    13  
    14  	b := make([]byte, 8)
    15  	for {
    16  		n, err := r.Read(b)
    17  		fmt.Printf("n = %v err = %v b = %v\n", n, err, b)
    18  		fmt.Printf("b[:n] = %q\n", b[:n])
    19  		if err == io.EOF {
    20  			break
    21  		}
    22  	}
    23  }
    24  

View as plain text