Skip to content

Commit ce45a6b

Browse files
author
libertyzhu
committed
Downloader支持设置dump_record_dir
1 parent 6e0837a commit ce45a6b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

qcloud_cos/cos_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3560,7 +3560,7 @@ def _check_all_upload_parts(self, bucket, key, uploadid, local_path, parts_num,
35603560
already_exist_parts[part_num] = part['ETag']
35613561
return True
35623562

3563-
def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, EnableCRC=False, progress_callback=None, **Kwargs):
3563+
def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, EnableCRC=False, progress_callback=None, DumpRecordDir=None, **Kwargs):
35643564
"""小于等于20MB的文件简单下载,大于20MB的文件使用续传下载
35653565
35663566
:param Bucket(string): 存储桶名称.
@@ -3596,7 +3596,7 @@ def download_file(self, Bucket, Key, DestFilePath, PartSize=20, MAXThread=5, Ena
35963596
callback = ProgressCallback(file_size, progress_callback)
35973597

35983598
downloader = ResumableDownLoader(self, Bucket, Key, DestFilePath, object_info, PartSize, MAXThread, EnableCRC,
3599-
callback, **Kwargs)
3599+
callback, DumpRecordDir, **Kwargs)
36003600
downloader.start()
36013601

36023602
def upload_file(self, Bucket, Key, LocalFilePath, PartSize=1, MAXThread=5, EnableMD5=False, progress_callback=None,

qcloud_cos/resumable_downloader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
class ResumableDownLoader(object):
1919
def __init__(self, cos_client, bucket, key, dest_filename, object_info, part_size=20, max_thread=5,
20-
enable_crc=False, progress_callback=None, **kwargs):
20+
enable_crc=False, progress_callback=None, dump_record_dir = None, **kwargs):
2121
self.__cos_client = cos_client
2222
self.__bucket = bucket
2323
self.__key = key
@@ -34,7 +34,10 @@ def __init__(self, cos_client, bucket, key, dest_filename, object_info, part_siz
3434
self.__finished_parts = []
3535
self.__lock = threading.Lock()
3636
self.__record = None # 记录当前的上下文
37-
self.__dump_record_dir = os.path.join(os.path.expanduser('~'), '.cos_download_tmp_file')
37+
if not dump_record_dir:
38+
self.__dump_record_dir = os.path.join(os.path.expanduser('~'), '.cos_download_tmp_file')
39+
else:
40+
self.__dump_record_dir = dump_record_dir
3841

3942
record_filename = self.__get_record_filename(bucket, key, self.__dest_file_path)
4043
self.__record_filepath = os.path.join(self.__dump_record_dir, record_filename)

0 commit comments

Comments
 (0)