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 : Find commonalities in two slices or arrays example
+6.1k Golang : Create new color from command line parameters
+29.5k Golang : Saving(serializing) and reading file with GOB
+9.7k Golang : Sort and reverse sort a slice of floats
+12.5k Golang : "https://" not allowed in import path
+14.6k Golang : How to get URL port?
+7.1k Golang : Transform lisp or spinal case to Pascal case example
+11.6k Golang : Display a text file line by line with line number example
+5.3k Golang : How to deal with configuration data?
+5.9k Facebook : How to force facebook to scrape latest URL link data?
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+37.5k Golang : Converting a negative number to positive number