Skip to content

Instantly share code, notes, and snippets.

@m87h
Created April 24, 2015 22:39
Show Gist options
  • Save m87h/21e71c66dd755c4cd787 to your computer and use it in GitHub Desktop.
Save m87h/21e71c66dd755c4cd787 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import sys
from string import zfill
from zipfile import ZipFile
def main(path, crc, *args):
with ZipFile(path, 'r') as zip:
for info in zip.infolist():
if zfill(format(info.CRC, 'x'), 8) == crc.lower():
sys.exit(0)
sys.exit(1)
if __name__ == '__main__':
if len(sys.argv) != 3:
print('usage: zip-contains-crc <zipfile> <crc>', file=sys.stderr)
sys.exit(2)
main(*sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment