# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
# This file contains miscellaneous utility functions that don't belong anywhere
# in particular.
import hashlib
def hash_file(path):
"""Hashes a file specified by the path given and returns the hex digest."""
# If the hashing function changes, this may invalidate lots of cached data.
# Don't change it lightly.
h = hashlib.sha1()
with open(path, 'rb') as fh:
while True:
data = fh.read(8192)
if not len(data):
break
h.update(data)
return h.hexdigest()