We first talked about the handy strings package back in Chapter 4, The Uses of Composite Types. This section will address the functions of the strings package that are related to file input and output.
The first part of str.go is shown in the following Go code:
package main import ( "fmt" "io" "os" "strings" )
The second code segment of str.go is as follows:
func main() { r := strings.NewReader("test") fmt.Println("r length:", r.Len())
The strings.NewReader() function creates a read-only Reader from a string. The strings.Reader object implements the io.Reader, io.ReaderAt, io.Seeker, io.WriterTo, io.ByteScanner, and io.RuneScanner interfaces.
The third part of str.go follows:
b := make([]byte, 1) for { n, err := r.Read(b) if...