19
19
from .parse_url import parse_url
20
20
21
21
CHUNK_SIZE = 512 * 1024 # 512KB
22
- TEMPFILE_SUFFIX = ".part"
23
22
home = osp .expanduser ("~" )
24
23
25
24
@@ -153,9 +152,7 @@ def download(
153
152
fuzzy: bool
154
153
Fuzzy extraction of Google Drive's file Id. Default is False.
155
154
resume: bool
156
- Resume interrupted transfers.
157
- Completed output files will be skipped.
158
- Partial tempfiles will be reused, if the transfer is incomplete.
155
+ Resume interrupted downloads while skipping completed ones.
159
156
Default is False.
160
157
format: str, optional
161
158
Format of Google Docs, Spreadsheets and Slides. Default is:
@@ -298,19 +295,14 @@ def download(
298
295
output = osp .join (output , filename_from_url )
299
296
300
297
if output_is_path :
301
-
302
- # Shortcut any 100% transfers to avoid excessive GETs,
303
- # when it's reasonable to assume that gdown would've been
304
- # using tempfiles and atomic renames before.
305
298
if resume and os .path .isfile (output ):
306
299
if not quiet :
307
- print (f"resume: already have { output } " )
300
+ print (f"Skipping already downloaded file { output } " , file = sys . stderr )
308
301
return output
309
302
310
- # Alternatively, resume mode can reuse partial tmp_files.
311
303
existing_tmp_files = []
312
304
for file in os .listdir (osp .dirname (output ) or "." ):
313
- if file .startswith (osp .basename (output )) and file . endswith ( TEMPFILE_SUFFIX ) :
305
+ if file .startswith (osp .basename (output )):
314
306
existing_tmp_files .append (osp .join (osp .dirname (output ), file ))
315
307
if resume and existing_tmp_files :
316
308
if len (existing_tmp_files ) != 1 :
@@ -328,13 +320,12 @@ def download(
328
320
)
329
321
return
330
322
tmp_file = existing_tmp_files [0 ]
331
- # Perhaps it should select the biggest one?
332
323
else :
333
324
resume = False
334
325
# mkstemp is preferred, but does not work on Windows
335
326
# https://github.com/wkentaro/gdown/issues/153
336
327
tmp_file = tempfile .mktemp (
337
- suffix = TEMPFILE_SUFFIX ,
328
+ suffix = tempfile . template ,
338
329
prefix = osp .basename (output ),
339
330
dir = osp .dirname (output ),
340
331
)
0 commit comments