]>
Commit | Line | Data |
---|---|---|
af92e385 ILT |
1 | // Copyright 2011 The Go Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style | |
3 | // license that can be found in the LICENSE file. | |
4 | ||
df4aa89a ILT |
5 | package bytes_test |
6 | ||
7 | import ( | |
4ccad563 | 8 | "bytes" |
df4aa89a | 9 | "encoding/base64" |
4ccad563 | 10 | "fmt" |
df4aa89a ILT |
11 | "io" |
12 | "os" | |
13 | ) | |
14 | ||
df4aa89a | 15 | func ExampleBuffer() { |
4ccad563 | 16 | var b bytes.Buffer // A Buffer needs no initialization. |
df4aa89a | 17 | b.Write([]byte("Hello ")) |
4ccad563 | 18 | fmt.Fprintf(&b, "world!") |
df4aa89a | 19 | b.WriteTo(os.Stdout) |
501699af | 20 | // Output: Hello world! |
df4aa89a ILT |
21 | } |
22 | ||
df4aa89a ILT |
23 | func ExampleBuffer_reader() { |
24 | // A Buffer can turn a string or a []byte into an io.Reader. | |
4ccad563 | 25 | buf := bytes.NewBufferString("R29waGVycyBydWxlIQ==") |
df4aa89a ILT |
26 | dec := base64.NewDecoder(base64.StdEncoding, buf) |
27 | io.Copy(os.Stdout, dec) | |
501699af | 28 | // Output: Gophers rule! |
df4aa89a | 29 | } |