crc32.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python3
  2. # Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  3. # All rights reserved.
  4. #
  5. # This software is supplied "AS IS" without any warranties.
  6. # RDA assumes no responsibility or liability for the use of the software,
  7. # conveys no license or title under any patent, copyright, or mask work
  8. # right to the product. RDA reserves the right to make changes in the
  9. # software without notification. RDA also make no representation or
  10. # warranty that such application will be suitable for the specified use
  11. # without further testing or modification.
  12. import argparse
  13. import sys
  14. import binascii
  15. DESCRIPTION = """
  16. Calculate CRC32 of files
  17. """
  18. def main():
  19. parser = argparse.ArgumentParser(description=DESCRIPTION)
  20. parser.add_argument(
  21. "fnames",
  22. metavar="FILE_NAME",
  23. nargs="+",
  24. help="file names to calculate CRC32")
  25. args = parser.parse_args()
  26. for fname in args.fnames:
  27. with open(fname, 'rb') as fh:
  28. data = fh.read()
  29. crc = binascii.crc32(data)
  30. print('%08x %s' % (crc, fname))
  31. if __name__ == "__main__":
  32. main()