Downloads¶
download
¶
File download utilities with aria2c acceleration and httpx fallback.
Replaces the PowerShell Save-File function from UmeAiRTUtils.psm1. Adds SHA256 checksum verification (a security improvement over the original).
verify_checksum(file_path, expected_sha256)
¶
Verify the SHA256 checksum of a downloaded file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the file to verify. |
required |
expected_sha256
|
str
|
Expected SHA256 hex digest (lowercase). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if checksum matches, False otherwise. |
Source code in src/utils/download.py
download_file(url, dest, *, checksum=None, force=False, quiet=True, aria2c_hint=None, log=None)
¶
Download a file from one or more URLs to a destination path.
When url is a list, each URL is tried in order — the first successful download wins. This enables transparent HuggingFace → ModelScope failover.
Tries aria2c first for speed, then falls back to httpx. Optionally verifies SHA256 checksum after download.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str | list[str]
|
Source URL(s) to download from. Pass a list for multi-source
fallback (e.g. |
required |
dest
|
Path | str
|
Destination file path. |
required |
checksum
|
str | None
|
Optional SHA256 hex digest for verification. |
None
|
force
|
bool
|
If True, re-download even if file exists. |
False
|
quiet
|
bool
|
If True (default), suppress aria2c console output. |
True
|
aria2c_hint
|
Path | None
|
Optional directory where aria2c may be found
(e.g. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the downloaded file. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If all URLs fail or checksum doesn't match. |
Source code in src/utils/download.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |