crc = 0
with open(self.locations("path"), "rb") as fp:
data = fp.read(settings.CRC_BUFFER_SIZE)
while len(data) > 0:
crc = zlib.crc32(data, crc)
data = fp.read(settings.CRC_BUFFER_SIZE)
self.crc = "{:0>8x}".format(crc & 0xffffffff) // right aligned with zero-padding, width of 8 chars
if commit:
self.save()
After Change
def compute_crc(self, commit=True):
crc = 0
with open(self.locations("path"), "rb") as fp:
for data in iter(lambda: fp.read(settings.CRC_BUFFER_SIZE), b""):
crc = zlib.crc32(data, crc)
self.crc = "{:0>8x}".format(crc & 0xffffffff) // right aligned with zero-padding, width of 8 chars