Golang bytes.Buffer.UnreadByte() function example
package bytes
UnreadByte unreads the last byte returned by the most recent read operation. If write has happened since the last read, UnreadByte returns an error.
Golang bytes.Buffer.UnreadByte() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBuffer([]byte("abcdefg"))
fmt.Println(string(buff.Next(3))) // read next 3 bytes
fmt.Println(buff.String()) // starts from d
buff.UnreadByte() // reset read position back to c (1 byte)
fmt.Println(buff.String())
}
Output :
abc
defg
cdefg
Reference :
Advertisement
Something interesting
Tutorials
+7.9k Golang : Trim everything onward after a word
+6.3k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+10.6k Golang : Bubble sort example
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+17.6k Convert JSON to CSV in Golang
+10.7k Golang : Underscore string example
+14.2k Golang : syscall.Socket example
+7.5k Golang : How to handle file size larger than available memory panic issue
+12.3k Golang : How to check if a string starts or ends with certain characters or words?
+3.6k Java : Get FX sentiment from website example
+9k Golang : Go as a script or running go with shebang/hashbang style