summaryrefslogtreecommitdiff
path: root/tests/basics/io_bytesio_ext.py
blob: 92e715178116cdafeee86cca3fd25fa8b3cd8ca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Extended stream operations on io.BytesIO

try:
    import io
except ImportError:
    print("SKIP")
    raise SystemExit

a = io.BytesIO(b"foobar")
a.seek(10)
print(a.read(10))

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())

a.seek(0)
arr = bytearray(10)
print(a.readinto(arr))
print(arr)