Skip to content

Commit a0d3aed

Browse files
committed
use hash method in find_dups
1 parent f1adb27 commit a0d3aed

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

examples/find_dups.py

+2-15
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,20 @@
88
"""
99

1010
from collections import defaultdict
11-
import hashlib
1211
import sys
1312

1413
from fs import open_fs
1514

1615

17-
def get_hash(bin_file):
18-
"""Get the md5 hash of a file."""
19-
file_hash = hashlib.md5()
20-
while True:
21-
chunk = bin_file.read(1024 * 1024)
22-
if not chunk:
23-
break
24-
file_hash.update(chunk)
25-
return file_hash.hexdigest()
26-
27-
2816
hashes = defaultdict(list)
2917
with open_fs(sys.argv[1]) as fs:
3018
for path in fs.walk.files():
31-
with fs.open(path, "rb") as bin_file:
32-
file_hash = get_hash(bin_file)
19+
file_hash = fs.hash(path, "md5")
3320
hashes[file_hash].append(path)
3421

3522
for paths in hashes.values():
3623
if len(paths) > 1:
3724
for path in paths:
38-
print(f" {path}")
25+
print(path)
3926
print()
4027

0 commit comments

Comments
 (0)