-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreader.py
More file actions
31 lines (19 loc) · 704 Bytes
/
Copy pathreader.py
File metadata and controls
31 lines (19 loc) · 704 Bytes
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
def read(filename):
with open(filename, "rb") as f:
# Reading and Saving
magic = f.read(4)
if magic != b"PHOE":
raise Exception("File type not supported/Wrong file type")
version = int.from_bytes(f.read(1), "little")
if version != 1:
raise Exception("Unsupported Version!")
msg_len = int.from_bytes(f.read(4), "little") # message length
msg = f.read(msg_len)
if len(msg) != msg_len:
raise Exception("File is corrupted")
return {
"magic": magic.decode(),
"version": version,
"msg_len": msg_len,
"msg": msg.decode()
}