Skip to content

Commit 820743c

Browse files
committed
Preallocate space on disk before downloading files
1 parent ab83427 commit 820743c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

update.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def download_file(session, url, dest):
2727
with session.get(url, stream=True, timeout=10) as r:
2828
r.raise_for_status()
2929
with open(dest, 'wb') as f:
30+
if 'Content-Length' in r.headers:
31+
length = int(r.headers['Content-Length'])
32+
f.truncate(length)
3033
shutil.copyfileobj(r.raw, f)
3134

3235
# Fix for "read-only" files on Windows

0 commit comments

Comments
 (0)