Skip to main content

tweak a few bits in s3hash

ID
1af899f
date
2023-08-21 12:01:29+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
2739502
message
tweak a few bits in s3hash
changed files
1 file, 10 additions, 2 deletions

Changed files

aws/s3hash.py (910) → aws/s3hash.py (1118)

diff --git a/aws/s3hash.py b/aws/s3hash.py
index 8367cc6..032ef4b 100755
--- a/aws/s3hash.py
+++ b/aws/s3hash.py
@@ -7,6 +7,8 @@ import argparse
 import hashlib
 import os
 
+import tqdm
+
 from _common import create_link_text, create_s3_session, parse_s3_uri
 
 
@@ -36,7 +38,13 @@ if __name__ == "__main__":
 
     h = hashlib.new(args.algorithm)
 
-    while chunk := s3_obj["Body"].read(8192):
-        h.update(chunk)
+    with tqdm.tqdm(total=s3_obj["ContentLength"], unit="B", unit_scale=True) as pbar:
+        while True:
+            chunk = s3_obj["Body"].read(8192)
+            pbar.update(len(chunk))
+            h.update(chunk)
+
+            if not chunk:
+                break
 
     print(h.hexdigest(), end="")