diff options
author | Frederick Muriuki Muriithi | 2024-12-20 12:34:17 -0600 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-12-20 12:34:17 -0600 |
commit | bb85bfe307231a3082681ff3ececb331a56b0bdc (patch) | |
tree | 4a82858261c388b21b84449a77c67de85f707437 /uploader/files/functions.py | |
parent | 959fb4bb4ec50af4bc28a4de1455d25ab82b10e8 (diff) | |
download | gn-uploader-bb85bfe307231a3082681ff3ececb331a56b0bdc.tar.gz |
Separate generic functions from chunking functions
Diffstat (limited to 'uploader/files/functions.py')
-rw-r--r-- | uploader/files/functions.py | 14 |
1 files changed, 2 insertions, 12 deletions
diff --git a/uploader/files/functions.py b/uploader/files/functions.py index d37a53e..5a3dece 100644 --- a/uploader/files/functions.py +++ b/uploader/files/functions.py @@ -1,7 +1,6 @@ """Utilities to deal with uploaded files.""" import hashlib from pathlib import Path -from typing import Iterator from datetime import datetime from flask import current_app @@ -9,6 +8,8 @@ from flask import current_app from werkzeug.utils import secure_filename from werkzeug.datastructures import FileStorage +from .chunks import chunked_binary_read + def save_file(fileobj: FileStorage, upload_dir: Path) -> Path: """Save the uploaded file and return the path.""" assert bool(fileobj), "Invalid file object!" @@ -29,17 +30,6 @@ def fullpath(filename: str): return Path(current_app.config["UPLOAD_FOLDER"], filename).absolute() -def chunked_binary_read(filepath: Path, chunksize: int = 2048) -> Iterator: - """Read a file in binary mode in chunks.""" - with open(filepath, "rb") as inputfile: - while True: - data = inputfile.read(chunksize) - if data != b"": - yield data - continue - break - - def sha256_digest_over_file(filepath: Path) -> str: """Compute the sha256 digest over a file's contents.""" filehash = hashlib.sha256() |