read_test.go 620 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package countconn_test
  2. import (
  3. "bytes"
  4. "fmt"
  5. "io"
  6. "os"
  7. "strings"
  8. "go.mindeco.de/logging/countconn"
  9. )
  10. func ExampleNewReader() {
  11. r := strings.NewReader("hello, world\n")
  12. rc := countconn.NewReader(r)
  13. n, err := io.Copy(os.Stdout, rc)
  14. fmt.Println(err)
  15. fmt.Println(n)
  16. fmt.Println(rc.N())
  17. // Output: hello, world
  18. // <nil>
  19. // 13
  20. // 13
  21. }
  22. func ExampleNewWriter() {
  23. var w bytes.Buffer
  24. wc := countconn.NewWriter(&w)
  25. n, err := io.Copy(wc, strings.NewReader("hello, world\n"))
  26. fmt.Print(w.String())
  27. fmt.Println(err)
  28. fmt.Println(n)
  29. fmt.Println(wc.N())
  30. // Output: hello, world
  31. // <nil>
  32. // 13
  33. // 13
  34. }