[bitbake-devel] [PATCH 2/2] bb/utils.py: implement (md5, sha1, sha256)_file in terms of hash_file
Rasmus Villemoes
rasmus.villemoes at prevas.dk
Tue Jul 10 14:06:12 UTC 2018
Testing on the largest tarball in my downloads dir (linux-4.15.7.tar.xz)
shows that this is ~twice as fast for md5 and ~35% faster for sha256.
Signed-off-by: Rasmus Villemoes <rasmus.villemoes at prevas.dk>
---
lib/bb/utils.py | 21 +++------------------
1 file changed, 3 insertions(+), 18 deletions(-)
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index cb7a6fa2..ef7fc932 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -547,12 +547,7 @@ def md5_file(filename):
Return the hex string representation of the MD5 checksum of filename.
"""
import hashlib
- m = hashlib.md5()
-
- with open(filename, "rb") as f:
- for line in f:
- m.update(line)
- return m.hexdigest()
+ return hash_file(hashlib.md5(), filename).hexdigest()
def sha256_file(filename):
"""
@@ -560,24 +555,14 @@ def sha256_file(filename):
filename.
"""
import hashlib
-
- s = hashlib.sha256()
- with open(filename, "rb") as f:
- for line in f:
- s.update(line)
- return s.hexdigest()
+ return hash_file(hashlib.sha256(), filename).hexdigest()
def sha1_file(filename):
"""
Return the hex string representation of the SHA1 checksum of the filename
"""
import hashlib
-
- s = hashlib.sha1()
- with open(filename, "rb") as f:
- for line in f:
- s.update(line)
- return s.hexdigest()
+ return hash_file(hashlib.sha1(), filename).hexdigest()
def preserved_envvars_exported():
"""Variables which are taken from the environment and placed in and exported
--
2.16.4
More information about the bitbake-devel
mailing list