-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathioUtils.py
44 lines (34 loc) · 1.05 KB
/
ioUtils.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import struct
# Big Endian
def read_int8(file) -> int:
entry = file.read(1)
return struct.unpack('>b', entry)[0]
def read_uint8(file) -> int:
entry = file.read(1)
return struct.unpack('B', entry)[0]
def read_int16(file) -> int:
entry = file.read(2)
return struct.unpack('>h', entry)[0]
def read_uint16(file) -> int:
entry = file.read(2)
return struct.unpack('>H', entry)[0]
def read_int32(file) -> int:
entry = file.read(4)
return struct.unpack('>i', entry)[0]
def read_uint32(file) -> int:
entry = file.read(4)
return struct.unpack('>I', entry)[0]
def read_int64(file) -> int:
entry = file.read(8)
return struct.unpack('>q', entry)[0]
def read_uint64(file) -> int:
entry = file.read(8)
return struct.unpack('>Q', entry)[0]
def read_string(file, maxLen = -1) -> str:
binaryString = b""
while maxLen == -1 or len(binaryString) < maxLen:
char = file.read(1)
if char == b'\x00':
break
binaryString += char
return binaryString.decode('utf-8', 'ignore')