fix: adjust seek offset for small files in createTorrentSum
parent
6215f3d01b
commit
253660d628
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue