Golang io.MultiReader function example
package io
Golang io.MultiReader function usage example
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
)
func main() {
reader := bytes.NewReader([]byte("abcdefghijkl"))
reader2 := bytes.NewReader([]byte("mnopqrstuvwxyz"))
buff := []io.Reader{reader, reader2}
// FROM http://golang.org/pkg/io/#MultiReader
// MultiReader returns a Reader that's the logical concatenation
// of the provided input readers. They're read sequentially.
combined := io.MultiReader(buff...)
data, _ := ioutil.ReadAll(combined)
fmt.Println(string(data))
}
Output :
abcdefghijklmnopqrstuvwxyz
Reference :
Advertisement
Something interesting
Tutorials
+23.6k Golang : Get ASCII code from a key press(cross-platform) example
+41.5k Golang : Convert string to array/slice
+12.9k Golang : Listen and Serve on sub domain example
+8.5k Golang : How to check if input string is a word?
+9.6k Android Studio : Indicate progression with ProgressBar example
+8.3k Golang : Find relative luminance or color brightness
+8.2k Golang : Randomize letters from a string example
+15.3k Golang : How to check if IP address is in range
+11.7k Golang : Simple file scaning and remove virus example
+20.4k Golang : Determine if directory is empty with os.File.Readdir() function
+8.9k Golang : Take screen shot of browser with JQuery example
+16k Golang : Read a file line by line