2016-07-29 21:00:25 +01:00
|
|
|
# Extended stream operations on io.BytesIO
|
|
|
|
try:
|
|
|
|
import uio as io
|
|
|
|
except ImportError:
|
|
|
|
import io
|
|
|
|
|
2017-05-12 21:28:07 +01:00
|
|
|
a = io.BytesIO(b"foobar")
|
|
|
|
a.seek(10)
|
|
|
|
print(a.read(10))
|
|
|
|
|
2016-07-29 21:00:25 +01:00
|
|
|
a = io.BytesIO()
|
|
|
|
print(a.seek(8))
|
|
|
|
a.write(b"123")
|
|
|
|
print(a.getvalue())
|
|
|
|
|
|
|
|
print(a.seek(0, 1))
|
|
|
|
|
|
|
|
print(a.seek(-1, 2))
|
|
|
|
a.write(b"0")
|
|
|
|
print(a.getvalue())
|
|
|
|
|
|
|
|
a.flush()
|
|
|
|
print(a.getvalue())
|
2016-10-09 10:01:02 +01:00
|
|
|
|
|
|
|
a.seek(0)
|
|
|
|
arr = bytearray(10)
|
|
|
|
print(a.readinto(arr))
|
|
|
|
print(arr)
|