4ccad563d2
From-SVN: r192704
30 lines
673 B
Go
30 lines
673 B
Go
// Copyright 2011 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package bytes_test
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func ExampleBuffer() {
|
|
var b bytes.Buffer // A Buffer needs no initialization.
|
|
b.Write([]byte("Hello "))
|
|
fmt.Fprintf(&b, "world!")
|
|
b.WriteTo(os.Stdout)
|
|
// Output: Hello world!
|
|
}
|
|
|
|
func ExampleBuffer_reader() {
|
|
// A Buffer can turn a string or a []byte into an io.Reader.
|
|
buf := bytes.NewBufferString("R29waGVycyBydWxlIQ==")
|
|
dec := base64.NewDecoder(base64.StdEncoding, buf)
|
|
io.Copy(os.Stdout, dec)
|
|
// Output: Gophers rule!
|
|
}
|