Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
bufio\bufio.go: Is Peek() in Reader incorrect? #39395
What version of Go are you using (
You're creating a new buffered reader for each Peek call, but re-using the file descriptor. The first Peek call advances the file offset, because it has to fill the buffer so that it can read. The second Peek call happens on a fresh bufio.Reader, which uses the same file descriptor to read data. That file descriptor is probably at EOF at that point.
If you change your program to re-use the buffered reader, you should see the results you expect: https://play.golang.org/p/ukUoAvmA3r2
For questions like these in the future, please use one of the community venues listed here: https://golang.org/help/#help