30 lines
745 B
Python
30 lines
745 B
Python
from typing import Generator, List, Tuple, Optional
|
|
from re import compile, Pattern
|
|
from zlib import crc32
|
|
|
|
|
|
class CRC32(object):
|
|
NAME: str = "CRC32"
|
|
EXT: List[str] = [".sfv"]
|
|
SYNTAX: List[Pattern] = [
|
|
compile(r'^;*$'),
|
|
compile(r'^.* [0-9a-fA-F]{8}$')
|
|
]
|
|
REGEX: Pattern = compile(r'[0-9a-fA-F]{8}')
|
|
|
|
def __init__(self):
|
|
self.cksum: int = 0
|
|
|
|
def gensum(self, data: bytes):
|
|
self.cksum = crc32(data, self.cksum)
|
|
|
|
def reset(self):
|
|
self.__init__()
|
|
|
|
def __repr__(self) -> str:
|
|
cstring = str(hex(self.cksum))[2:].upper()
|
|
return ''.join([((8 - len(cstring)) * "0"), cstring])
|
|
|
|
def __eq__(self, other) -> bool:
|
|
return self.__repr__() == other.upper()
|