szha commented on a change in pull request #7322: add verification to gluon 
dataset
URL: https://github.com/apache/incubator-mxnet/pull/7322#discussion_r131475235
 
 

 ##########
 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:
   a hash can be in any form (bytes, long long, string with different radix). 
hex there is to signify what the input should be (i.e. hexadecimal string).
 
----------------------------------------------------------------
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

Reply via email to