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
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+11.3k Golang : How to use if, eq and print properly in html template
+12k Golang : Clean formatting/indenting or pretty print JSON result
+23.9k Golang : Use regular expression to validate domain name
+7.1k Golang : Validate credit card example
+24k Golang : Call function from another package
+6k Linux/MacOSX : Search for files by filename and extension with find command
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+16.1k Golang : Generate universally unique identifier(UUID) example
+5.3k Javascript : Shuffle or randomize array example
+6.7k Golang : Reverse by word