On Wednesday, January 11, 2012 2:01:20 PM UTC+1, Mostafa Hajizadeh wrote:
bufio doesn't have a function to read a specific number of bytes from a Reader. It was easy to write using ReadByte, but I thought having that might be very handy, specially while dealing with protocols and file formats in which you know how many bytes are you going to read, which is a very common case.
I think there already is full control over the upper limit (N) of the number of bytes bufio.Read will read by passing a slice with len() = N.
// Along the lines of e.g.:
var dest = make([]byte, 64*1024)
n, err := myBufioReader.Read(dest[x:x+42]) // At most 42 bytes