-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
45 lines (37 loc) · 1.09 KB
/
util.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
45
import struct
def read8(file):
return struct.unpack("b", file.read(1))[0]
def readByte(file):
return struct.unpack("B", file.read(1))[0]
def read16(file, le=True):
if le:
return struct.unpack("<h", file.read(2))[0]
else:
return struct.unpack(">h", file.read(2))[0]
def readu16(file, le=True):
if le:
return struct.unpack("<H", file.read(2))[0]
else:
return struct.unpack(">H", file.read(2))[0]
def read32(file, le=True):
if le:
return struct.unpack("<i", file.read(4))[0]
else:
return struct.unpack(">i", file.read(4))[0]
def readu32(file, le=True):
if le:
return struct.unpack("<I", file.read(4))[0]
else:
return struct.unpack(">I", file.read(4))[0]
def readfloat(file, le=True):
if le:
return struct.unpack("<f", file.read(4))[0]
else:
return struct.unpack(">f", file.read(4))[0]
def getString(file):
result = ""
tmpChar = file.read(1)
while ord(tmpChar) != 0:
result += tmpChar
tmpChar =file.read(1)
return result