voxcity.downloader.utilsΒΆ
FunctionsΒΆ
|
Download a file from a URL and save it locally with retry and streaming. |
Module ContentsΒΆ
- voxcity.downloader.utils.download_file(url, filename, *, timeout=60, max_retries=3, initial_delay=2.0, backoff_factor=2.0, chunk_size=8192)[source]ΒΆ
Download a file from a URL and save it locally with retry and streaming.
Uses streaming to avoid loading large files entirely into memory and retries on transient network failures with exponential backoff.
- Parameters:
url (str) β URL of the file to download.
filename (str) β Local path where the downloaded file will be saved.
timeout (int) β Request timeout in seconds (default 60).
max_retries (int) β Number of retry attempts on failure (default 3).
initial_delay (float) β Seconds to wait before the first retry (default 2.0).
backoff_factor (float) β Multiplier for delay between retries (default 2.0).
chunk_size (int) β Bytes per chunk when streaming (default 8192).
- Raises:
requests.HTTPError β If download fails after all retries.
Example
>>> download_file('https://example.com/file.pdf', 'local_file.pdf')