Skip to content

Commit 6be14da

Browse files
Merge pull request #857 from bridadan/fix_big_download
Fix downloading of Mbed 2 when zip is too big
2 parents e69923c + 93a0a04 commit 6be14da

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mbed/mbed.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,14 @@ def fetch_rev(url, rev):
389389
try:
390390
if not os.path.exists(rev_file):
391391
action("Downloading library build \"%s\" (might take a while)" % rev)
392-
outfd = open(rev_file, 'wb')
393392
inurl = urlopen(url)
394-
outfd.write(inurl.read())
395-
outfd.close()
396-
except:
393+
with open(rev_file, 'wb') as outfd:
394+
data = None
395+
while data != '':
396+
# Download and write the data in 1 MB chunks
397+
data = inurl.read(1024 * 1024)
398+
outfd.write(data)
399+
except Exception:
397400
if os.path.isfile(rev_file):
398401
os.remove(rev_file)
399402
raise Exception(128, "Download failed!\nPlease try again later.")

0 commit comments

Comments
 (0)