Skip to content

Commit

Permalink
Merge pull request #857 from bridadan/fix_big_download
Browse files Browse the repository at this point in the history
Fix downloading of Mbed 2 when zip is too big
  • Loading branch information
theotherjimmy authored Mar 4, 2019
2 parents e69923c + 93a0a04 commit 6be14da
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions mbed/mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,14 @@ def fetch_rev(url, rev):
try:
if not os.path.exists(rev_file):
action("Downloading library build \"%s\" (might take a while)" % rev)
outfd = open(rev_file, 'wb')
inurl = urlopen(url)
outfd.write(inurl.read())
outfd.close()
except:
with open(rev_file, 'wb') as outfd:
data = None
while data != '':
# Download and write the data in 1 MB chunks
data = inurl.read(1024 * 1024)
outfd.write(data)
except Exception:
if os.path.isfile(rev_file):
os.remove(rev_file)
raise Exception(128, "Download failed!\nPlease try again later.")
Expand Down

0 comments on commit 6be14da

Please sign in to comment.