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
+12.2k Golang : Simple client-server HMAC authentication without SSL example
+10.2k Golang : Text file editor (accept input from screen and save to file)
+19.2k Golang : Delete item from slice based on index/key position
+7.4k Linux : How to fix Brother HL-1110 printing blank page problem
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+24.5k Golang : Time slice or date sort and reverse sort example
+6.3k Apt-get to install and uninstall Golang
+20.6k Nginx + FastCGI + Go Setup.
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+18.4k Golang : How to remove certain lines from a file
+4.9k Unix/Linux : secure copying between servers with SCP command examples