From 78bab6f49006fbcf0ca3a0ba63572c2169d12507 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Fri, 21 Aug 2020 14:07:28 -0700 Subject: Make chunk size a constant --- wikiget/__init__.py | 1 + wikiget/dl.py | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wikiget/__init__.py b/wikiget/__init__.py index dccd7a5..8437ebf 100644 --- a/wikiget/__init__.py +++ b/wikiget/__init__.py @@ -21,6 +21,7 @@ from .version import __version__ as wikiget_version # set some global constants BLOCKSIZE = 65536 +CHUNKSIZE = 1024 DEFAULT_SITE = 'commons.wikimedia.org' DEFAULT_PATH = '/w/' USER_AGENT = ('wikiget/{} (https://github.com/clpo13/wikiget) ' diff --git a/wikiget/dl.py b/wikiget/dl.py index 6a9b0e2..6cbe8df 100644 --- a/wikiget/dl.py +++ b/wikiget/dl.py @@ -23,7 +23,7 @@ from mwclient import APIError, InvalidResponse, LoginError, Site from requests import ConnectionError, HTTPError from tqdm import tqdm -from . import DEFAULT_SITE, USER_AGENT +from . import CHUNKSIZE, DEFAULT_SITE, USER_AGENT from .validations import valid_file, verify_hash @@ -137,12 +137,13 @@ def download(dl, args): leave_bars = True else: leave_bars = False - with tqdm(leave=leave_bars, total=file_size, unit='B', - unit_scale=True, unit_divisor=1024) as progress_bar: + with tqdm(leave=leave_bars, total=file_size, + unit='B', unit_scale=True, + unit_divisor=CHUNKSIZE) as progress_bar: with fd: res = site.connection.get(file_url, stream=True) progress_bar.set_postfix(file=dest, refresh=False) - for chunk in res.iter_content(1024): + for chunk in res.iter_content(CHUNKSIZE): fd.write(chunk) progress_bar.update(len(chunk)) -- cgit v1.2.3