Golang bytes.Buffer.ReadFrom() function example
package bytes
ReadFrom reads data from input buffer until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.
Golang bytes.Buffer.ReadFrom() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
bufferA := bytes.NewBuffer([]byte("abcd"))
bufferB := bytes.NewBuffer(nil)
n, err := bufferB.ReadFrom(bufferA)
fmt.Printf("%v %s %d\n", err, string(bufferB.Bytes()), n)
}
Output :
<nil> abcd 4
Reference :
Advertisement
Something interesting
Tutorials
+21.4k Golang : simulate tail -f or read last line from log file example
+8.1k Golang : Generate Codabar
+14.8k Golang : Read integer from file into array
+9.7k PHP : Convert(cast) bigInt to string
+37.8k Golang : How to iterate over a []string(array)
+7.6k Android Studio : Indicate progression with ProgressBar example
+16.1k Golang : Find smallest number in array
+7.6k Golang : Convert(cast) []byte to io.Reader type
+6.3k Golang : Word limiter example
+14.5k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+18.2k Golang : Convert(cast) bytes.Buffer or bytes.NewBuffer type to io.Reader
+50.3k Golang : How to get struct field and value by name