##// END OF EJS Templates
largefiles: reuse hexsha1() to centralize hash calculation logic into it...
FUJIWARA Katsunori -
r31652:d5cbbee5 default
parent child Browse files
Show More
@@ -373,11 +373,8 b' def copyandhash(instream, outfile):'
373 373 def hashfile(file):
374 374 if not os.path.exists(file):
375 375 return ''
376 hasher = hashlib.sha1('')
377 376 with open(file, 'rb') as fd:
378 for data in util.filechunkiter(fd):
379 hasher.update(data)
380 return hasher.hexdigest()
377 return hexsha1(fd)
381 378
382 379 def getexecutable(filename):
383 380 mode = os.stat(filename).st_mode
@@ -398,11 +395,11 b' def urljoin(first, second, *arg):'
398 395 url = join(url, a)
399 396 return url
400 397
401 def hexsha1(data):
398 def hexsha1(fileobj):
402 399 """hexsha1 returns the hex-encoded sha1 sum of the data in the file-like
403 400 object data"""
404 401 h = hashlib.sha1()
405 for chunk in util.filechunkiter(data):
402 for chunk in util.filechunkiter(fileobj):
406 403 h.update(chunk)
407 404 return h.hexdigest()
408 405
General Comments 0
You need to be logged in to leave comments. Login now