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
+7.5k Golang : Rename part of filename
+26.8k Golang : Convert file content into array of bytes
+16k Golang : Read large file with bufio.Scanner cause token too long error
+13.4k Golang : Verify token from Google Authenticator App
+15.6k Golang : Force download file example
+14.1k Golang : Check if a file exist or not
+9.8k Golang : Qt get screen resolution and display on center example
+6.5k Elasticsearch : Shutdown a local node
+7.7k Golang : Test if an input is an Armstrong number example
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+18.1k Golang : Check if a directory exist or not
+4.7k Unix/Linux : How to pipe/save output of a command to file?