MCPcopy Index your code
hub / github.com/PaddlePaddle/FastDeploy / download_file

Function download_file

fastdeploy/utils.py:400–425  ·  view source on GitHub ↗

Download file with progress bar

(url, save_path)

Source from the content-addressed store, hash-verified

398
399
400def download_file(url, save_path):
401 """Download file with progress bar"""
402 try:
403 response = requests.get(url, stream=True)
404 response.raise_for_status()
405
406 total_size = int(response.headers.get("content-length", 0))
407 progress_bar = tqdm(
408 total=total_size,
409 unit="iB",
410 unit_scale=True,
411 desc=f"Downloading {os.path.basename(url)}",
412 )
413
414 with open(save_path, "wb") as f:
415 for chunk in response.iter_content(chunk_size=1024):
416 if chunk: # filter out keep-alive chunks
417 f.write(chunk)
418 progress_bar.update(len(chunk))
419
420 progress_bar.close()
421 return True
422 except Exception as e:
423 if os.path.exists(save_path):
424 os.remove(save_path)
425 raise RuntimeError(f"Download failed: {e!s}")
426
427
428def extract_tar(tar_path, output_dir):

Callers 1

download_modelFunction · 0.85

Calls 5

writeMethod · 0.80
getMethod · 0.45
updateMethod · 0.45
closeMethod · 0.45
existsMethod · 0.45

Tested by

no test coverage detected