summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/Lib/io.py b/Lib/io.py
index ed94665..0054d42 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -659,6 +659,11 @@ class BytesIO(BufferedIOBase):
raise ValueError("write to closed file")
n = len(b)
newpos = self._pos + n
+ if newpos > len(self._buffer):
+ # Inserts null bytes between the current end of the file
+ # and the new write position.
+ padding = '\x00' * (newpos - len(self._buffer) - n)
+ self._buffer[self._pos:newpos - n] = padding
self._buffer[self._pos:newpos] = b
self._pos = newpos
return n