diff options
author | Guido van Rossum <guido@python.org> | 2007-07-21 00:25:15 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-07-21 00:25:15 (GMT) |
commit | b972a78e17beeb997d809d87f2e422e6622efd52 (patch) | |
tree | a0ecff06dd600468f399afeeccfc3a62c20c5cd3 /Lib | |
parent | d4eda825c7ed83822868e2e6d794e2ad4dc6c955 (diff) | |
download | cpython-b972a78e17beeb997d809d87f2e422e6622efd52.zip cpython-b972a78e17beeb997d809d87f2e422e6622efd52.tar.gz cpython-b972a78e17beeb997d809d87f2e422e6622efd52.tar.bz2 |
SF patch# 1757683 by Alexandre Vassalotti. Add support for
seeking/writing beyond EOF to io.BytesIO.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/io.py | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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 |