Example: How to use TeeReader from IO Package in Golang?
TeeReader returns a Reader that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w.
Example
package main
import (
"bytes"
"io"
"fmt"
"strings"
)
func main() {
testString := strings.NewReader("Jobs, Code, Videos and News for Go hackers.")
var bufferRead bytes.Buffer
example := io.TeeReader(testString, &bufferRead)
readerMap := make([]byte, testString.Len())
length, err := example.Read(readerMap)
fmt.Printf("\nBufferRead: %s", &bufferRead)
fmt.Printf("\nRead: %s", readerMap)
fmt.Printf("\nLength: %d, Error:%v", length, err)
}
Output
BufferRead: Jobs, Code, Videos and News for Go hackers.
Read: Jobs, Code, Videos and News for Go hackers.
Length: 43, Error:
Most Helpful This Week
Print index and element or data from Array, Slice and Map
How to Convert string to float type in Go?
How to use wildcard or a variable in our URL for complex routing?
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
Regular expression to validate common Credit Card Numbers
Various examples of Carbon date-time package in Golang
User Defined Function Types in Golang
Functions mess (recursive anonymous function) in Golang
Example: Arrays of Arrays, Arrays of Slices, Slices of Arrays and Slices of Slices
Example Function that takes an interface type as value and pointer?