Skip to content

Instantly share code, notes, and snippets.

@clayg
Created June 25, 2020 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clayg/df7c276a43c3618d7897ba50ae87ea9d to your computer and use it in GitHub Desktop.
Save clayg/df7c276a43c3618d7897ba50ae87ea9d to your computer and use it in GitHub Desktop.
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