| 151 | |
| 152 | |
| 153 | def http_get(url: str, temp_file: IO) -> None: |
| 154 | req = requests.get(url, stream=True) |
| 155 | content_length = req.headers.get('Content-Length') |
| 156 | total = int(content_length) if content_length is not None else None |
| 157 | progress = tqdm(unit="B", total=total) |
| 158 | for chunk in req.iter_content(chunk_size=1024): |
| 159 | if chunk: # filter out keep-alive new chunks |
| 160 | progress.update(len(chunk)) |
| 161 | temp_file.write(chunk) |
| 162 | progress.close() |
| 163 | |
| 164 | |
| 165 | def get_from_cache(url: str, cache_dir: Union[str, Path] = None) -> str: |