Created
June 25, 2020 18:44
-
-
Save clayg/df7c276a43c3618d7897ba50ae87ea9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
import ctypes.util | |
import struct | |
import sys | |
import textwrap | |
import zlib | |
lib_name = ctypes.util.find_library('erasurecode') | |
if not lib_name: | |
lib_name = 'liberasurecode.so.1' | |
libec = ctypes.CDLL(lib_name) | |
libec_crc_alt = getattr(libec, 'liberasurecode_crc32_alt', libec.crc32) | |
def crc_alt(data): | |
return ctypes.c_uint(libec_crc_alt(0, ctypes.c_char_p(data), len(data))).value | |
for frag in sys.argv[1:]: | |
with open(frag, 'rb') as fp: | |
header = fp.read(80) | |
print(textwrap.dedent( | |
''' | |
Frag: {} | |
Stored CRC: {:08x} | |
zlib CRC: {:08x} | |
libec CRC: {:08x} | |
''' | |
).lstrip().format( | |
frag, | |
struct.unpack('I', header[67:71])[0], | |
zlib.crc32(header[:59]), | |
crc_alt(header[:59]), | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment