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
+17.3k Golang : How to tell if a file is compressed either gzip or zip ?
+13.4k Golang : Generate Code128 barcode
+5.8k Golang : Markov chains to predict probability of next state example
+13.6k Golang : Get user input until a command or receive a word to stop
+9.4k Golang : Generate EAN barcode
+12.1k Golang : Perform sanity checks on filename example
+9.7k Golang : List available AWS regions
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+47.8k Golang : Convert int to byte array([]byte)
+5.3k Python : Convert(cast) string to bytes example
+8.4k Your page has meta tags in the body instead of the head