Golang bytes.Buffer.ReadBytes() function example
package bytes
ReadBytes reads until the first occurrence of delimiter in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in the given delimiter.
Golang bytes.Buffer.ReadBytes() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBufferString("abcd*ef")
rb, err := buff.ReadBytes('*') // end with 's'.... plural!
fmt.Printf("%v %d %s\n", err, rb, string(rb))
}
Output :
[97 98 99 100 42] abcd*
Reference :
Advertisement
Something interesting
Tutorials
+7.8k Golang : Reverse a string with unicode
+6.7k Golang : Derive cryptographic key from passwords with Argon2
+22.1k Golang : Repeat a character by multiple of x factor
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+13.3k Golang : Linear algebra and matrix calculation example
+4.7k Fix Google Analytics Redundant Hostnames problem
+12.3k Golang : Get month name from date example
+7.5k Golang : How to stop user from directly running an executable file?
+20.7k Android Studio : AlertDialog and EditText to get user string input example
+13.2k Golang : Convert(cast) int to int64
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function