2014-04-18 07:56:18 -04:00
|
|
|
import binascii
|
|
|
|
|
2014-04-18 18:01:29 -04:00
|
|
|
def insert_crc(i_filename, fbi_mode=False, o_filename=None):
|
2014-04-18 07:56:18 -04:00
|
|
|
if o_filename is None:
|
2014-04-18 18:01:29 -04:00
|
|
|
o_filename = i_filename
|
|
|
|
|
|
|
|
with open(i_filename, 'rb') as f:
|
|
|
|
fdata = f.read()
|
|
|
|
fcrc = binascii.crc32(fdata).to_bytes(4, byteorder="big")
|
|
|
|
flength = len(fdata).to_bytes(4, byteorder="big")
|
2014-04-18 07:56:18 -04:00
|
|
|
|
2014-04-18 18:01:29 -04:00
|
|
|
with open(o_filename, 'wb') as f:
|
|
|
|
if fbi_mode:
|
|
|
|
f.write(flength)
|
|
|
|
f.write(fcrc)
|
|
|
|
f.write(fdata)
|
|
|
|
else:
|
|
|
|
f.write(fdata)
|
|
|
|
f.write(fcrc)
|