master
Charles Iliya Krempeaux 2019-09-05 18:43:53 -07:00
parent 06edca9192
commit a0e5c6762a
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
package buffers_test
import (
"github.com/reiver/go-buffers"
"fmt"
)
func ExampleWriter() {
var buffer [256]byte
var p []byte = buffer[:]
writer := buffers.NewWriter(p)
data := []byte("Hello world!")
n, err := writer.Write(data)
if nil != err {
fmt.Printf("ERROR: Problem writing: %s\n", err)
return
}
fmt.Printf("Wrote %d bytes to the buffer.\n", n)
fmt.Printf("Those %d bytes in the buffer have a value of “%s”.\n", n, buffer)
// Output:
// Wrote 12 bytes to the buffer.
// Those 12 bytes in the buffer have a value of “Hello world!”.
}