mirror of
https://github.com/python/cpython.git
synced 2024-11-24 10:24:35 +08:00
SF patch# 1757683 by Alexandre Vassalotti. Add support for
seeking/writing beyond EOF to io.BytesIO.
This commit is contained in:
parent
d4eda825c7
commit
b972a78e17
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user