INNER CODE UNIT · Python
download
steineggerlab/foldcomp · foldcomp/setup.py:36
async def download(url, output, chunks=16):
async with httpx.AsyncClient(follow_redirects=True) as client:
file_size = await get_size(client, url)
if file_size == -1:
return
# check that file is not already downloaded
if os.path.exists(output) and os.path.getsize(output) == file_size:
return
# create chunks amount of ranges based on file_size
ranges = []
if file_size > 10 * 1024 * 1024:
for i in range(chunks):
start = i * file_size // chunks
end = min((i + 1) * file_size // chunks, file_size) - 1
output_chunk = f"{output}.{i}"
# adjust start if output_chunk already partially exists