io_bytesio_ext.py 403 B

12345678910111213141516171819202122232425262728
  1. # Extended stream operations on io.BytesIO
  2. try:
  3. import uio as io
  4. except ImportError:
  5. import io
  6. a = io.BytesIO(b"foobar")
  7. a.seek(10)
  8. print(a.read(10))
  9. a = io.BytesIO()
  10. print(a.seek(8))
  11. a.write(b"123")
  12. print(a.getvalue())
  13. print(a.seek(0, 1))
  14. print(a.seek(-1, 2))
  15. a.write(b"0")
  16. print(a.getvalue())
  17. a.flush()
  18. print(a.getvalue())
  19. a.seek(0)
  20. arr = bytearray(10)
  21. print(a.readinto(arr))
  22. print(arr)