INNER CODE UNIT · Python

download_range

steineggerlab/foldcomp · foldcomp/setup.py:14

async def download_range(client, url, start, end, output, mode):
    curr_start = start
    with open(output, mode) as f:
        while True:
            try:
                async with client.stream(
                    "GET", url, headers={"Range": f"bytes={curr_start}-{end}"}
                ) as response:
                    async for chunk in response.aiter_raw():
                        f.write(chunk)
            except:
                # sometimes the connection is closed by the server
                # so we retry the download
                f.flush()
                os.fsync(f.fileno())
                # set start to current written position
                curr_start = start + f.tell()
                if curr_start < end:

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…