Commit e7c222ca authored by Andrew Gerrand's avatar Andrew Gerrand

bytes: make examples work in playground

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/6633050
parent 241b2360
...@@ -5,23 +5,24 @@ ...@@ -5,23 +5,24 @@
package bytes_test package bytes_test
import ( import (
. "bytes" "bytes"
"encoding/base64" "encoding/base64"
"fmt"
"io" "io"
"os" "os"
) )
func ExampleBuffer() { func ExampleBuffer() {
var b Buffer // A Buffer needs no initialization. var b bytes.Buffer // A Buffer needs no initialization.
b.Write([]byte("Hello ")) b.Write([]byte("Hello "))
b.Write([]byte("world!")) fmt.Fprintf(&b, "world!")
b.WriteTo(os.Stdout) b.WriteTo(os.Stdout)
// Output: Hello world! // Output: Hello world!
} }
func ExampleBuffer_reader() { func ExampleBuffer_reader() {
// A Buffer can turn a string or a []byte into an io.Reader. // A Buffer can turn a string or a []byte into an io.Reader.
buf := NewBufferString("R29waGVycyBydWxlIQ==") buf := bytes.NewBufferString("R29waGVycyBydWxlIQ==")
dec := base64.NewDecoder(base64.StdEncoding, buf) dec := base64.NewDecoder(base64.StdEncoding, buf)
io.Copy(os.Stdout, dec) io.Copy(os.Stdout, dec)
// Output: Gophers rule! // Output: Gophers rule!
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment