The bytes standard Go package contains functions for working with byte slices in the same way that the strings standard Go package helps you to work with strings. The name of the Go source code file is bytes.go, and it will be presented in three code portions.
The first part of bytes.go follows:
package main import ( "bytes" "fmt" "io" "os" )
The second code portion of bytes.go contains the following Go code:
func main() { var buffer bytes.Buffer buffer.Write([]byte("This is")) fmt.Fprintf(&buffer, " a string!\n") buffer.WriteTo(os.Stdout) buffer.WriteTo(os.Stdout)
First, you create a new bytes.Buffer variable and you put data into it using buffer.Write() and fmt.Fprintf(). Then, you call buffer.WriteTo() twice.
The first buffer.WriteTo() call...