async download w/ aiofiles/http

PHOTO EMBED

Tue Dec 20 2022 07:19:11 GMT+0000 (Coordinated Universal Time)

Saved by @justquick #python

async def async_http_download(src_url, dest_file, chunk_size=65536):
    async with aiofiles.open(dest_file, 'wb') as fd:
        async with aiohttp.ClientSession() as session:
            async with session.get(src_url) as resp:
                async for chunk in resp.content.iter_chunked(chunk_size):
                    await fd.write(chunk)
content_copyCOPY