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
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)
+6.5k Golang : Convert an executable file into []byte example
+13.4k Golang : Read from buffered reader until specific number of bytes
+8.2k Golang : Metaprogramming example of wrapping a function
+32.4k Golang : Math pow(the power of x^y) example
+6.9k Golang : Fibonacci number generator examples
+6.2k PHP : Get client IP address
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+5.4k Golang *File points to a file or directory ?
+48.1k Golang : How to convert JSON string to map and slice