piiswrong commented on a change in pull request #7322: add verification to
gluon dataset
URL: https://github.com/apache/incubator-mxnet/pull/7322#discussion_r131473239
##########
File path: python/mxnet/gluon/utils.py
##########
@@ -119,7 +120,33 @@ def _indent(s_, numSpaces):
return s
-def download(url, path=None, overwrite=False):
+def verified_sha1(file_path, sha1hex):
+ """Check whether the sha1 hash of the file content matches the expected
hash.
+
+ Parameters
+ ----------
+ file_path : str
+ Path to the file.
+ sha1hex : str
+ Expected sha1 hash in hexadecimal digits.
+
+ Returns
+ -------
+ bool
+ Whether the file content matches the expected hash.
+ """
+ sha1 = hashlib.sha1()
+ with open(file_path, 'rb') as f:
+ while True:
+ data = f.read(1048576)
+ if not data:
+ break
+ sha1.update(data)
+
+ return sha1.hexdigest() == sha1hex
+
+
+def download(url, path=None, overwrite=False, sha1hex=None):
Review comment:
sha1hex -> sha1_hash
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services