Skip to content

Commit

Permalink
Merge pull request #211 from fls-bioinformatics-core/reimplement-md5sums
Browse files Browse the repository at this point in the history
bcftbx/Md5sum: reimplement 'md5sum' function to reduce memory footprint
  • Loading branch information
pjbriggs committed Dec 16, 2022
2 parents 3a0df01 + a6b6761 commit 670163c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions bcftbx/Md5sum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#
# Md5sum.py: classes and functions for md5 checksum operations
# Copyright (C) University of Manchester 2012-2020 Peter Briggs
# Copyright (C) University of Manchester 2012-2022 Peter Briggs
#
########################################################################
#
Expand Down Expand Up @@ -471,20 +471,19 @@ def md5sum(f):
Returns:
Md5sum digest for the named file.
"""
chksum = hashlib.md5()
close_fp = False
try:
fp = io.open(f,"rb",buffering=BLOCKSIZE)
fp = open(f,"rb")
close_fp = True
except TypeError:
fp = f
for block in iter(fp.read,''):
if block:
chksum.update(block)
else:
while True:
buf = fp.read(BLOCKSIZE)
if not buf:
break
chksum.update(buf)
if close_fp:
fp.close()
return chksum.hexdigest()

0 comments on commit 670163c

Please sign in to comment.