fix: adjust seek offset for small files in createTorrentSum

devel
Juan Manuel Bardallo 2026-09-17 12:21:58 +02:00
parent 6215f3d01b
commit 253660d628
1 changed files with 6 additions and 1 deletions

View File

@ -96,8 +96,13 @@ def get_md5_sum(file_path, megabytes=1):
Se utiliza para crear el archivo ".sum" (para transferencias Unicast y Multicast).
"""
hash_md5 = hashlib.md5()
file_size = os.path.getsize(file_path)
seek_offset = -megabytes * 1024 * 1024
if file_size < (-seek_offset):
seek_offset = -file_size
with open(file_path, "rb") as f:
f.seek(-megabytes * 1024 * 1024, os.SEEK_END)
f.seek(seek_offset, os.SEEK_END)
data = f.read(megabytes * 1024 * 1024)
hash_md5.update(data)
return hash_md5.hexdigest()