From a0e5c6762ad860ba1635a74be5faf337c2a4af9e Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Thu, 5 Sep 2019 18:43:53 -0700 Subject: [PATCH] exam[ple --- example_writer_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 example_writer_test.go diff --git a/example_writer_test.go b/example_writer_test.go new file mode 100644 index 0000000..fbef24a --- /dev/null +++ b/example_writer_test.go @@ -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!”. +}