Skip to content

Instantly share code, notes, and snippets.

@bloodeagle40234
Last active July 2, 2020 05:23
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 bloodeagle40234/3e1a7767a84f1aae6352ef5ea9e034be to your computer and use it in GitHub Desktop.
Save bloodeagle40234/3e1a7767a84f1aae6352ef5ea9e034be to your computer and use it in GitHub Desktop.
diff --git a/libec_crcs_original.py b/libec_crcs.py
index a80c823..518c737 100644
--- a/libec_crcs_original.py
+++ b/libec_crcs.py
@@ -13,7 +13,15 @@ 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
+ return ctypes.c_uint(libec_crc_alt(0, ctypes.c_char_p(data), len(data))).value
+
+
+def crc_zlib(data):
+ zlib_crc = zlib.crc32(data)
+ if zlib_crc < 0:
+ zlib_crc = zlib_crc & 0xffffffff
+ return zlib_crc
+
for frag in sys.argv[1:]:
with open(frag, 'rb') as fp:
@@ -29,6 +37,6 @@ for frag in sys.argv[1:]:
).lstrip().format(
frag,
struct.unpack('I', header[67:71])[0],
- zlib.crc32(header[:59]),
+ crc_zlib(header[:59]),
crc_alt(header[:59]),
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment