On Sun, Jul 9, 2017 at 5:47 AM, Juliusz Chroboczek <j...@irif.fr> wrote:
>
> I cannot find anything in the documentation about how bufio.Scanner
> behaves when the underlying io.Reader does partial reads.

It will behave correctly, doing additional reads as needed to complete a token.

The Go documentation generally doesn't go out of its way to explain
that code will behave as documented.  The Scanner.Scan method never
promises to do only a single Read; it promises to advance to the next
token, and that is what it does.


> I'm using a Scanner to parse a stream of tokens that arrives over a TCP
> socket.  The stream is a sequence of lines terminated by \n.  Do I have
> a guarantee that the final \n will be passed to my custom scan function
> and the result passed to the Scan function even if the connection hangs
> just after the \n?

Yes (assuming the underlying Reader returns the final \n).


> Do similar properties hold for bufio.Reader (i.e., that the final octet
> will be passed to the client even if the connection hangs)?

Yes (assuming the underlying Reader returns the octet).


> Shall I submit an issue?

No.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to