Golang bytes.Reader.UnreadByte() function example
package bytes
Unread a byte from current offset.
Golang bytes.Reader.UnreadByte() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
reader := bytes.NewReader([]byte("abc"))
var b1,b2,b3 byte
b1, err := reader.ReadByte() // read 1 byte
fmt.Printf("%v %s \n", err, string(b1))
b2, err2 := reader.ReadByte() // read 1 byte
fmt.Printf("%v %s \n", err2, string(b2))
//unread 1 byte
reader.UnreadByte()
b3, err3 := reader.ReadByte() // read 1 byte
fmt.Printf("%v %s \n", err3, string(b3))
}
Output :
<nil> a
<nil> b
<nil> b
Reference :
Advertisement
Something interesting
Tutorials
+8.8k Golang : Heap sort example
+46.2k Golang : Read tab delimited file with encoding/csv package
+15.2k Golang : Accurate and reliable decimal calculations
+11.4k Golang : Delay or limit HTTP requests example
+21.2k Golang : How to get time zone and load different time zone?
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+10.1k Golang : Compare files modify date example
+27.2k Golang : Find files by name - cross platform example
+15.8k Golang : How to login and logout with JWT example
+12.7k Golang : Sort and reverse sort a slice of bytes
+9.7k Golang : Find correlation coefficient example