Kaydet (Commit) 844f757a authored tarafından Alexandre Vassalotti's avatar Alexandre Vassalotti

Cleaned up io._BytesIO.write().

I am amazed that the old code, for inserting null-bytes, actually
worked. Who wrote that thing? Oh, it is me... doh.
üst cd8001c8
...@@ -826,14 +826,14 @@ class _BytesIO(BufferedIOBase): ...@@ -826,14 +826,14 @@ class _BytesIO(BufferedIOBase):
n = len(b) n = len(b)
if n == 0: if n == 0:
return 0 return 0
newpos = self._pos + n pos = self._pos
if newpos > len(self._buffer): if pos > len(self._buffer):
# Inserts null bytes between the current end of the file # Inserts null bytes between the current end of the file
# and the new write position. # and the new write position.
padding = b'\x00' * (newpos - len(self._buffer) - n) padding = b'\x00' * (pos - len(self._buffer))
self._buffer[self._pos:newpos - n] = padding self._buffer += padding
self._buffer[self._pos:newpos] = b self._buffer[pos:pos + n] = b
self._pos = newpos self._pos += n
return n return n
def seek(self, pos, whence=0): def seek(self, pos, whence=0):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment