Skip to content

Commit

Permalink
Preallocate space on disk before downloading files
Browse files Browse the repository at this point in the history
  • Loading branch information
puigru committed Oct 2, 2019
1 parent ab83427 commit 820743c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def download_file(session, url, dest):
with session.get(url, stream=True, timeout=10) as r:
r.raise_for_status()
with open(dest, 'wb') as f:
if 'Content-Length' in r.headers:
length = int(r.headers['Content-Length'])
f.truncate(length)
shutil.copyfileobj(r.raw, f)

# Fix for "read-only" files on Windows
Expand Down

0 comments on commit 820743c

Please sign in to comment.