Running this on Python 3.5.1 on OSX:
import io
b = io.BytesIO()
b.write(b'222')
print(b.getvalue())
b.truncate(0)
b.write(b'222')
print(b.getvalue())
Produces:
b'222'
b'\x00\x00\x00222'
So truncating the BytesIO
somehow causes it to start inserting extra zero bytes in the beginning? Why?