diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 023478aa78c6a0..b3a8f37d68acdb 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -937,10 +937,8 @@ def write(self, b): return 0 pos = self._pos if pos > len(self._buffer): - # Inserts null bytes between the current end of the file - # and the new write position. - padding = b'\x00' * (pos - len(self._buffer)) - self._buffer += padding + # Pad buffer to pos with null bytes. + self._buffer.resize(pos) self._buffer[pos:pos + n] = b self._pos += n return n