capstone.utils.downloader
handle_download(url, dest_path, num_threads=4)
Downloads a file from the specified URL to the given destination path.
The function attempts to download the file using parallel chunking if the server supports byte-range requests and the file size is known. Otherwise, it falls back to a single-threaded download. The number of parallel threads can be specified.
If the download fails, the partially downloaded file is removed and the error is logged.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url
|
str
|
The URL of the file to download. |
required |
dest_path
|
Path
|
The local path where the downloaded file will be saved. |
required |
num_threads
|
int
|
Number of parallel threads to use for downloading. Defaults to 4. |
4
|
Raises:
Type | Description |
---|---|
Exception
|
If the download fails for any reason other than KeyboardInterrupt. |
Notes
- In testing, more than 4 threads caused 503 errors on some servers.
Source code in capstone/utils/downloader.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|