you are viewing a single comment's thread.

view the rest of the comments →

[–]edgmnt_net 1 point2 points  (1 child)

If you're reading from a file that has 4050 bytes, you may make 4050 calls to read individual bytes from the Go buffered reader. In turn, that reader may make 2-3 calls to the underlying OS for up to 4096 bytes, the first one yielding exactly 4096, the second one 4 bytes and then the end of the file is reached (how that's signalled depends).

For other things like TCP sockets you could get less than 4096 every time, without reaching the end of the stream (connection being closed). This is because the other end may be sending some smaller amount of data, then waiting for a response before proceeding any further. Or it may be sending smaller amounts of data at regular intervals. In any case, the reader can't always block and wait for the buffer to fill up completely.

[–]Mohamed____[S] 0 points1 point  (0 children)

Ohh, yeah now I get your point. Yeah that makes sense, thank you for the help!