From 677d8a251f9c78a3f201e75fb228575a1e6e166c Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 25 Sep 2020 15:37:09 -0700 Subject: [PATCH] Don't worry with .seek if we're doing a fulldownload plan. --- voussoirkit/downloady.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/voussoirkit/downloady.py b/voussoirkit/downloady.py index 1ad347f..e59b6bf 100644 --- a/voussoirkit/downloady.py +++ b/voussoirkit/downloady.py @@ -81,8 +81,13 @@ def download_plan(plan): if directory != '': os.makedirs(directory, exist_ok=True) touch(localname) - file_handle = open(localname, 'r+b') - file_handle.seek(plan['seek_to']) + if plan['plan_type'] in ['resume', 'partial']: + file_handle = open(localname, 'r+b') + file_handle.seek(plan['seek_to']) + bytes_downloaded = plan['seek_to'] + elif plan['plan_type'] == 'fulldownload': + file_handle = open(localname, 'wb') + bytes_downloaded = 0 if plan['header_range_min'] is not None: plan['headers']['range'] = 'bytes={min}-{max}'.format( @@ -90,13 +95,6 @@ def download_plan(plan): max=plan['header_range_max'], ) - if plan['plan_type'] == 'resume': - bytes_downloaded = plan['seek_to'] - elif plan['plan_type'] == 'partial': - bytes_downloaded = plan['seek_to'] - else: - bytes_downloaded = 0 - download_stream = request( 'get', plan['url'],