I'm trying to read the length of some metadata from a .lrf file. (Used with the program LoLReplay)
There's not really documentation on these files, but I have already figured out how to do this in C++. I'm trying to re-write the project in python for multiple reasons, but I come across an error.
To first explain, the .lrf file has metadata immediately at the start of the file in this format:
first 4 bytes are for something I have no clue about.
next 4 bytes store the length of the metadata in hexidecimal, up until the end of the metadata, which after is the actual contents of the replay.
bytes after the initial 8 bytes are the metadata in json format
The problem I'm having is actually reading the metadata length. This is the current function I have:
def getMetaLength(self):
try:
file = open(self.file,"r")
except IOError:
print ("Failed to open file.")
file.close()
#We need to skip the first 4 bytes.
file.read(4)
mdlength = file.read(4)
print(hex(mdlength))
file.close()
When I call this function, the shell returns a traceback stating:
Traceback (most recent call last):
File "C:\Users\Donald\python\lolcogs\lolcogs_main.py", line 6, in <module>
lolcogs.getMetaLength()
File "C:\Users\Donald\python\lolcogs\LoLCogs.py", line 20, in getMetaLength
file.read(4)
File "C:\Python32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3648: character maps to <undefined>
My best guess is that read() is trying to read characters that are encoded in some unicode format, but these are definitely just bytes that I am attempting to read. Is there a way to read these as bytes? Also, is there a better way to skip bytes when you are attempting to read a file?