package main import ( "bufio" "fmt" "strings" ) func main() { str := "This is a test string" reader := bufio.NewReader(strings.NewReader(str)) peeked, _ := reader.Peek(4) fmt.Printf("Peeked bytes: %q\n", peeked) // Read the next byte nextByte, _ := reader.ReadByte() fmt.Printf("Next byte: %q\n", nextByte) }
package main import ( "bufio" "fmt" "os" ) func main() { file, _ := os.Open("example.txt") reader := bufio.NewReader(file) peeked, _ := reader.Peek(10) fmt.Printf("Peeked bytes: %q\n", peeked) }In this example, we create a bufio.Reader from a file and peek at the first 10 bytes. We then print the peeked bytes. The package library used in this example is "bufio".