]> Cypherpunks repositories - gostls13.git/commitdiff
bytes: add example for (*Buffer).Bytes
authorFederico Guerinoni <guerinoni.federico@gmail.com>
Sun, 8 Nov 2020 14:35:35 +0000 (15:35 +0100)
committerIan Lance Taylor <iant@golang.org>
Wed, 11 Nov 2020 20:51:00 +0000 (20:51 +0000)
Change-Id: I49ac604530fff7928fa15de07563418b104da5e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/268260
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Giovanni Bajo <rasky@develer.com>

src/bytes/example_test.go

index 5ba7077c1de8532ada65dbef0980f501bcd17e2d..ae93202b5706e12da11cb8866af8f6a9d75b5745 100644 (file)
@@ -30,6 +30,13 @@ func ExampleBuffer_reader() {
        // Output: Gophers rule!
 }
 
+func ExampleBuffer_Bytes() {
+       buf := bytes.Buffer{}
+       buf.Write([]byte{'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'})
+       os.Stdout.Write(buf.Bytes())
+       // Output: hello world
+}
+
 func ExampleBuffer_Grow() {
        var b bytes.Buffer
        b.Grow(64)