Golang bytes.Buffer.UnreadRune() function example
package bytes
UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
Golang bytes.Buffer.UnreadRune() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBuffer([]byte("abcdefg"))
rune, _, _ := buff.ReadRune()
fmt.Println(string(rune))
// remainder runes
fmt.Println(string(buff.Bytes()))
buff.UnreadRune()
// back to beginning
fmt.Println(string(buff.Bytes()))
}
Output :
a
bcdefg
abcdefg
Reference :
Advertisement
Something interesting
Tutorials
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+10.7k Golang : Underscore string example
+4.9k Javascript : How to get width and height of a div?
+20.6k Golang : Secure(TLS) connection between server and client
+17.6k Golang : delete and modify XML file content
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+9.6k Javascript : Read/parse JSON data from HTTP response
+13.2k CodeIgniter : "Fatal error: Cannot use object of type stdClass as array" message
+13.8k Golang : Gin framework accept query string by post request example
+29.5k Golang : Saving(serializing) and reading file with GOB