Golang bufio.Peek() function example
package bufio
Peek returns the next n bytes without advancing the reader. The bytes stop being valid at the next read call. If Peek returns fewer than n bytes, it also returns an error explaining why the read is short. The error is ErrBufferFull if n is larger than b's buffer size.
Golang bufio.Peek() function example
readbuffer := bytes.NewBuffer([]byte("12345678"))
reader := bufio.NewReader(readbuffer)
peekbuffer, _ := reader.Peek(4)
fmt.Println(string(peekbuffer))
Output :
1234
Advertisement
Something interesting
Tutorials
+13.6k Golang : Qt progress dialog example
+12.1k Golang : Sort and reverse sort a slice of runes
+7.3k Golang : File system scanning
+12.5k Golang : HTTP response JSON encoded data
+7k Golang : Find the shortest line of text example
+10.9k Nginx : TLS 1.2 support
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+10.2k Golang : Use regular expression to get all upper case or lower case characters example
+6.2k PHP : How to handle URI or URL with non-ASCII characters such as Chinese/Japanese/Korean(CJK) ?
+32.7k Golang : Regular Expression for alphanumeric and underscore
+55.3k Golang : Unmarshal JSON from http response