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
+18.9k Golang : Read input from console line
+14.6k Golang : Execute function at intervals or after some delay
+10.3k Golang : Convert file unix timestamp to UTC time example
+4.9k JQuery : Calling a function inside Jquery(document) block
+12.1k Golang : convert(cast) string to integer value
+18.4k Golang : Logging with logrus
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+5.9k Golang : Extract unicode string from another unicode string example
+8.6k Golang : Another camera capture GUI application with GTK and OpenCV
+7.1k Golang : Array mapping with Interface
+8.7k Golang : Find duplicate files with filepath.Walk