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
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+16k Golang : How to reverse elements order in map ?
+16.5k Golang : Check if a string contains multiple sub-strings in []string?
+18.5k Golang : Set, Get and List environment variables
+9.2k Golang : How to control fmt or log print format?
+8.5k Android Studio : Import third-party library or package into Gradle Scripts
+13.5k Golang : Count number of runes in string
+7.4k Golang : Hue, Saturation and Value(HSV) with OpenCV example
+13.6k Android Studio : Password input and reveal password example
+16.4k Golang : Convert slice to array
+25.3k Golang : Convert uint value to string type