mpl's suggestion to move io.EOF check closer to error generation point.