From 4d5c3d59f32b80638d82373d33a476652520e260 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 25 Apr 2019 18:29:46 +0200 Subject: test API --- check/app/utils/file_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'check/app/utils/file_utils.py') 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 -- cgit v1.2.3-70-g09d2