Skip to content

Commit 17fd383

Browse files
committed
Fix downloading of Mbed 2 when zip is too big
The Mbed 2 zip was being downloaded into memory. This downloads the zip in 1 MB chunks then writes them to disk to avoid running out of memory.
1 parent e69923c commit 17fd383

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mbed/mbed.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,13 @@ 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()
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)
396399
except:
397400
if os.path.isfile(rev_file):
398401
os.remove(rev_file)

0 commit comments

Comments
 (0)