Skip to content

Instantly share code, notes, and snippets.

@FRex
Created May 3, 2023 23:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FRex/a81f9a75e4ed772fc0e4e3f24c13517d to your computer and use it in GitHub Desktop.
Save FRex/a81f9a75e4ed772fc0e4e3f24c13517d to your computer and use it in GitHub Desktop.
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