Open files in 'rb' (read binary) mode to prevent useless default utf8 encoding in python3, without breaking python2 compatibility. Reported-by: Tharre <tharre3@gmail.com>
16 lines
360 B
Text
16 lines
360 B
Text
#!/usr/bin/env python
|
|
"""Calculate the sha256 digest of a given file."""
|
|
import hashlib, os, subprocess, sys
|
|
|
|
subprocess.check_call([
|
|
'redo-ifchange',
|
|
sys.argv[2],
|
|
], close_fds=False)
|
|
|
|
h = hashlib.sha256()
|
|
f = open(sys.argv[2], 'rb')
|
|
while 1:
|
|
b = f.read(65536)
|
|
if not b: break
|
|
h.update(b)
|
|
open(sys.argv[3], 'w').write(h.hexdigest() + '\n')
|