Golang bufio.ReadBytes() function example
package bufio
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 delimiter. For simple uses, a Scanner may be more convenient.
Golang bufio.ReadBytes() function usage example
readbuffer := bytes.NewBuffer([]byte("abcd#fg"))
reader := bufio.NewReader(readbuffer)
buffer, err := reader.ReadBytes('#') // # is our delimiter
fmt.Printf("%s \n", string(buffer))
Output :
abcd
Advertisement
Something interesting
Tutorials
+18.4k Golang : Logging with logrus
+31.9k Golang : Convert an image file to []byte
+25.9k Golang : How to read integer value from standard input ?
+17.4k Golang : Check if IP address is version 4 or 6
+15.2k Golang : Get HTTP protocol version example
+13.4k Golang : Increment string example
+21.2k Golang : How to force compile or remove object files first before rebuild?
+5.1k Golang : Check if a word is countable or not
+9.6k Golang : Sort and reverse sort a slice of floats
+6k PageSpeed : Clear or flush cache on web server
+8.6k Golang : Progress bar with ∎ character
+11.6k Golang : Convert(cast) float to int