From c373b8817f89d11cb1ac43a59ab1644f679da66c Mon Sep 17 00:00:00 2001 From: HawkLiking Date: Mon, 28 Oct 2019 22:58:26 +0100 Subject: [PATCH 1/3] Fix truncated byte (issue #35) --- pySmartDL/pySmartDL.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index 2f993aa..9ee8c15 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -684,12 +684,12 @@ def _calc_chunk_size(filesize, threads, minChunkFile): args = [] pos = 0 - chunk = filesize/threads + chunk = round(filesize/threads) for i in range(threads): startByte = pos endByte = pos + chunk - if endByte > filesize-1: - endByte = filesize-1 + if endByte > filesize: + endByte = filesize args.append((startByte, endByte)) pos += chunk+1 From d5984bc3b9468289bf932303c4b7c98a2753dca3 Mon Sep 17 00:00:00 2001 From: HawkLiking Date: Tue, 29 Oct 2019 08:31:08 +0100 Subject: [PATCH 2/3] Avoid round down --- pySmartDL/pySmartDL.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index 9ee8c15..01a8656 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -684,7 +684,7 @@ def _calc_chunk_size(filesize, threads, minChunkFile): args = [] pos = 0 - chunk = round(filesize/threads) + chunk = math.ceil(filesize/threads) for i in range(threads): startByte = pos endByte = pos + chunk From de9aa25263374867d0294e7ebd502ee032556337 Mon Sep 17 00:00:00 2001 From: HawkLiking Date: Tue, 29 Oct 2019 19:08:36 +0100 Subject: [PATCH 3/3] Roll back to filesize-1; add round chunck size in threads verif --- pySmartDL/pySmartDL.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pySmartDL/pySmartDL.py b/pySmartDL/pySmartDL.py index 01a8656..d321b96 100644 --- a/pySmartDL/pySmartDL.py +++ b/pySmartDL/pySmartDL.py @@ -679,7 +679,7 @@ def _calc_chunk_size(filesize, threads, minChunkFile): if not filesize: return [(0, 0)] - while filesize/threads < minChunkFile and threads > 1: + while math.ceil(filesize/threads) < minChunkFile and threads > 1: threads -= 1 args = [] @@ -688,8 +688,8 @@ def _calc_chunk_size(filesize, threads, minChunkFile): for i in range(threads): startByte = pos endByte = pos + chunk - if endByte > filesize: - endByte = filesize + if endByte > filesize-1: + endByte = filesize-1 args.append((startByte, endByte)) pos += chunk+1