From 7661ba9a2cf9ae4f7515c21aab10d8869da1d7e5 Mon Sep 17 00:00:00 2001 From: Matteo Campinoti Date: Fri, 10 Nov 2023 12:35:10 +0100 Subject: [PATCH] utils:functions - fix get_eof when file size is smaller than chunk size --- acacore/utils/functions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/acacore/utils/functions.py b/acacore/utils/functions.py index f8668e9..51db7f2 100644 --- a/acacore/utils/functions.py +++ b/acacore/utils/functions.py @@ -128,7 +128,8 @@ def get_eof(path: Path, chunk_size: int = 1024) -> bytes: bytes: The contents of the last chunk of the file as a bytes object. """ with path.open("rb") as f: - f.seek(path.stat().st_size - chunk_size) + file_size: int = path.stat().st_size + f.seek(file_size if chunk_size > file_size else chunk_size) return f.read(chunk_size)