Add helper function hash_file.
This commit is contained in:
parent
2d73e59abf
commit
9a1caee412
1 changed files with 10 additions and 0 deletions
|
@ -4,6 +4,7 @@ codebase but don't deserve to be methods of any class.
|
|||
'''
|
||||
|
||||
import datetime
|
||||
import hashlib
|
||||
import math
|
||||
import mimetypes
|
||||
import os
|
||||
|
@ -161,6 +162,15 @@ def get_mimetype(filepath):
|
|||
mimetype = mimetypes.guess_type(filepath)[0]
|
||||
return mimetype
|
||||
|
||||
def hash_file(filepath, hasher):
|
||||
bytestream = read_filebytes(filepath)
|
||||
for chunk in bytestream:
|
||||
hasher.update(chunk)
|
||||
return hasher.hexdigest()
|
||||
|
||||
def hash_file_md5(filepath):
|
||||
return hash_file(filepath, hasher=hashlib.md5())
|
||||
|
||||
def hyphen_range(s):
|
||||
'''
|
||||
Given a string like '1-3', return numbers (1, 3) representing lower
|
||||
|
|
Loading…
Reference in a new issue