# Copyright 2018 Mike "KemoNine" Crosson # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Borrowed from the web: https://www.joelverhagen.com/blog/2011/02/md5-hash-of-file-in-python/ import hashlib def md5Checksum(filePath): with open(filePath, 'rb') as fh: m = hashlib.md5() while True: data = fh.read(8192) if not data: break m.update(data) return m.hexdigest() def check_hash(map_file, md5_file): published_md5 = None with open(md5_file, 'r') as f: published_md5 = f.readline().strip().split()[0] map_md5 = md5Checksum(map_file) return published_md5 == map_md5