Skip to content

Commit 76b8057

Browse files
author
libertyzhu
committed
download_file support MaxPartCount param
1 parent bade7aa commit 76b8057

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

qcloud_cos/cos_client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4037,7 +4037,8 @@ def _check_all_upload_parts(self, bucket, key, uploadid, local_path, parts_num,
40374037
already_exist_parts[part_num] = part['ETag']
40384038
return True
40394039

4040-
def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, EnableCRC=False, progress_callback=None, DumpRecordDir=None, KeySimplifyCheck=True, DisableTempDestFilePath=False, **Kwargs):
4040+
def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, EnableCRC=False, progress_callback=None,
4041+
DumpRecordDir=None, KeySimplifyCheck=True, DisableTempDestFilePath=False, MaxPartCount=10000, **Kwargs):
40414042
"""小于等于20MB的文件简单下载,大于20MB的文件使用续传下载
40424043
40434044
:param Bucket(string): 存储桶名称.
@@ -4049,10 +4050,11 @@ def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, Ena
40494050
:param DumpRecordDir(string): 指定保存断点信息的文件路径
40504051
:param KeySimplifyCheck(bool): 是否对Key进行posix路径语义归并检查
40514052
:param DisableTempDestFilePath(bool): 简单下载写入目标文件时,不使用临时文件
4053+
:param MaxPartCount(int): 分块下载的最大分块数
40524054
:param kwargs(dict): 设置请求headers.
40534055
"""
40544056
logger.debug("Start to download file, bucket: {0}, key: {1}, dest_filename: {2}, part_size: {3}MB,\
4055-
max_thread: {4}".format(Bucket, Key, DestFilePath, PartSize, MAXThread))
4057+
max_thread: {4}, max_part_count: {5}".format(Bucket, Key, DestFilePath, PartSize, MAXThread, MaxPartCount))
40564058

40574059
head_headers = dict()
40584060
# SSE-C对象在head时也要求传入加密头域
@@ -4075,7 +4077,7 @@ def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, Ena
40754077
if progress_callback:
40764078
callback = ProgressCallback(file_size, progress_callback)
40774079

4078-
downloader = ResumableDownLoader(self, Bucket, Key, DestFilePath, object_info, PartSize, MAXThread, EnableCRC,
4080+
downloader = ResumableDownLoader(self, Bucket, Key, DestFilePath, object_info, PartSize, MAXThread, MaxPartCount, EnableCRC,
40794081
callback, DumpRecordDir, KeySimplifyCheck, **Kwargs)
40804082
downloader.start()
40814083

qcloud_cos/resumable_downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class ResumableDownLoader(object):
2020
def __init__(self, cos_client, bucket, key, dest_filename, object_info, part_size=20, max_thread=5,
21-
enable_crc=False, progress_callback=None, dump_record_dir=None, key_simplify_check=True, **kwargs):
21+
max_part_count=100, enable_crc=False, progress_callback=None, dump_record_dir=None, key_simplify_check=True, **kwargs):
2222
self.__cos_client = cos_client
2323
self.__bucket = bucket
2424
self.__key = key
@@ -30,7 +30,7 @@ def __init__(self, cos_client, bucket, key, dest_filename, object_info, part_siz
3030
self.__headers = kwargs
3131
self.__key_simplify_check = key_simplify_check
3232

33-
self.__max_part_count = 100 # 取决于服务端是否对并发有限制
33+
self.__max_part_count = max_part_count # 取决于服务端是否对并发有限制
3434
self.__min_part_size = 1024 * 1024 # 1M
3535
self.__part_size = self.__determine_part_size_internal(int(object_info['Content-Length']), part_size)
3636
self.__finished_parts = []

0 commit comments

Comments
 (0)