-
-
Save FRex/a81f9a75e4ed772fc0e4e3f24c13517d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import hashlib | |
import queue | |
import sys | |
def main(argv): | |
for fname in argv: | |
try: | |
with open(fname, "rb") as f: | |
h = hashlib.sha1() | |
q = queue.Queue(maxsize=32) | |
def reader(): | |
while True: | |
data = f.read(512 * 1024) | |
q.put(data) | |
if not data: | |
break | |
def hasher(): | |
while True: | |
x = q.get() | |
h.update(x) | |
if not x: | |
break | |
job = threading.Thread(target=reader) | |
job.daemon = True | |
job.start() | |
hasher() | |
job.join() | |
print(f"{h.hexdigest()} *{fname}") | |
except Exception as ex: | |
print(f"{fname} - {ex}") | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment