]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/bytes/example_test.go
bytes: add Buffer.Available and Buffer.AvailableBuffer
[gostls13.git] / src / bytes / example_test.go
index e5b7b60dbba6728904eefc1f5d92017a1a8a6125..41a5e2e5bf64ccd11220aee53f23b76c5562e5ac 100644 (file)
@@ -11,6 +11,7 @@ import (
        "io"
        "os"
        "sort"
+       "strconv"
        "unicode"
 )
 
@@ -37,6 +38,18 @@ func ExampleBuffer_Bytes() {
        // Output: hello world
 }
 
+func ExampleBuffer_AvailableBuffer() {
+       var buf bytes.Buffer
+       for i := 0; i < 4; i++ {
+               b := buf.AvailableBuffer()
+               b = strconv.AppendInt(b, int64(i), 10)
+               b = append(b, ' ')
+               buf.Write(b)
+       }
+       os.Stdout.Write(buf.Bytes())
+       // Output: 0 1 2 3
+}
+
 func ExampleBuffer_Cap() {
        buf1 := bytes.NewBuffer(make([]byte, 10))
        buf2 := bytes.NewBuffer(make([]byte, 0, 10))