Allow downloading to non-existant directory

This commit is contained in:
Sybren A. Stüvel 2016-03-15 15:35:28 +01:00
parent 7520421083
commit 5730f43848

View File

@ -143,6 +143,8 @@ async def download_to_file(url, filename, chunk_size=100 * 1024, *, future: asyn
# Download the file in a different thread. # Download the file in a different thread.
def download_loop(): def download_loop():
os.makedirs(os.path.dirname(filename), exist_ok=True)
with closing(req), open(filename, 'wb') as outfile: with closing(req), open(filename, 'wb') as outfile:
for block in req.iter_content(chunk_size=chunk_size): for block in req.iter_content(chunk_size=chunk_size):
if is_cancelled(future): if is_cancelled(future):