buffer: return io.ErrUnexpectedEOF

Fixes the returned error (see  #252) and introduces some small optimizations