Improve buffer handling for io.read().