summaryrefslogtreecommitdiff
path: root/check/app/utils
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2019-04-25 18:29:46 +0200
committerJules Laplace <julescarbon@gmail.com>2019-04-25 18:29:46 +0200
commit4d5c3d59f32b80638d82373d33a476652520e260 (patch)
tree88edd56458963229511b54276586c236604504b6 /check/app/utils
parent4f4df4d4e38f8ce27dc7e471359f9f644ca74092 (diff)
test API
Diffstat (limited to 'check/app/utils')
-rw-r--r--check/app/utils/file_utils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/check/app/utils/file_utils.py b/check/app/utils/file_utils.py
index 1ed1833..a185cf4 100644
--- a/check/app/utils/file_utils.py
+++ b/check/app/utils/file_utils.py
@@ -352,6 +352,16 @@ def sha256(fp_in, block_size=65536):
sha256.update(block)
return sha256.hexdigest()
+def sha256_stream(stream, block_size=65536):
+ """Generates SHA256 hash for a file stream (from Flask)
+ :param fp_in: (FileStream) stream object
+ :param block_size: (int) byte size of block
+ :returns: (str) hash
+ """
+ sha256 = hashlib.sha256()
+ for block in iter(lambda: stream.read(block_size), b''):
+ sha256.update(block)
+ return sha256.hexdigest()
def sha256_tree(sha256):
"""Split hash into branches with tree-depth for faster file indexing