]> granicus.if.org Git - python/commitdiff
SF patch# 1757683 by Alexandre Vassalotti. Add support for
authorGuido van Rossum <guido@python.org>
Sat, 21 Jul 2007 00:25:15 +0000 (00:25 +0000)
committerGuido van Rossum <guido@python.org>
Sat, 21 Jul 2007 00:25:15 +0000 (00:25 +0000)
seeking/writing beyond EOF to io.BytesIO.

Lib/io.py

index ed946659ef37e70898610b091ed39f7ea46ffa71..0054d42ea3e84415d507a1515b13664ceba7f86a 100644 (file)
--- 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