Peeking content
In the previous example, we fixed a number of bytes in order to store the content at every read before printing it. Some functionality is offered by the bufio package that makes it possible to use an underlying buffer that is not directly controlled by the user, and makes it possible to execute a very important operation named peek.
Peeking is the ability to read content without advancing the reader cursor. Here, under the hood, the peeked data is stored in the buffer. Each reading operation checks whether there's data in this buffer and if there is any, that data is returned while removing it from the buffer. This works like a queue (first in, first out).
The possibilities that this simple operation opens are endless, and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access