Skip to content

Instantly share code, notes, and snippets.

@tipabu
Created February 20, 2017 19:39
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 tipabu/1c7ff115b303b303553e365eb055829c to your computer and use it in GitHub Desktop.
Save tipabu/1c7ff115b303b303553e365eb055829c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import struct
import sys
import zlib
def check_archive(fragment_archive):
with open(fragment_archive, 'rb') as fp:
meta = fp.read(59)
if len(meta) != 59:
raise ValueError('Incomplete metadata!')
if len(fp.read(8)) != 8:
raise ValueError('Incomplete header! '
'Missing/incomplete magic/version')
crc = fp.read(4)
if len(crc) != 4:
raise ValueError('Incomplete header! Missing/incomplete crc')
meta_crc = zlib.crc32(meta) & 0xffffffff
recorded_crc, = struct.unpack_from('I', crc)
return meta_crc == recorded_crc
if __name__ == '__main__':
if len(sys.argv) < 2:
exit('Missing expected argument: fragment_archive')
if len(sys.argv) == 2:
if check_archive(sys.argv[1]):
print 'first frag checksum OK'
else:
exit('checksum mismatch!')
else:
for frag_archive in sys.argv[1:]:
if check_archive(frag_archive):
print '%s: ok' % frag_archive
else:
print '%s: ERROR' % frag_archive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment