GFDownloadTask¶
API Reference / Standard / 类索引
- 路径:
addons/gf/standard/utilities/io/gf_download_task.gd - 模块:
Standard - 继承:
RefCounted - API:
public - 类别:运行时句柄 (
runtime_handle) - 首次版本:
3.17.0
通用下载任务描述。 只记录下载 URL、目标路径、校验信息和运行状态,不假设下载内容的业务语义。
成员概览¶
| 类型 | 名称 | 签名 |
|---|---|---|
| 枚举 | Status |
enum Status |
| 属性 | task_id |
var task_id: int = 0 |
| 属性 | url |
var url: String = "" |
| 属性 | target_path |
var target_path: String = "" |
| 属性 | temp_path |
var temp_path: String = "" |
| 属性 | segment_path |
var segment_path: String = "" |
| 属性 | headers |
var headers: PackedStringArray = PackedStringArray() |
| 属性 | expected_sha256 |
var expected_sha256: String = "" |
| 属性 | resume |
var resume: bool = true |
| 属性 | overwrite |
var overwrite: bool = true |
| 属性 | max_retries |
var max_retries: int = 0 |
| 属性 | retry_count |
var retry_count: int = 0 |
| 属性 | retry_delay_seconds |
var retry_delay_seconds: float = 0.0 |
| 属性 | retry_not_before_msec |
var retry_not_before_msec: int = 0 |
| 属性 | metadata |
var metadata: Dictionary = {} |
| 属性 | status |
var status: Status = Status.QUEUED |
| 属性 | received_bytes |
var received_bytes: int = 0 |
| 属性 | total_bytes |
var total_bytes: int = -1 |
| 属性 | response_code |
var response_code: int = 0 |
| 属性 | error |
var error: String = "" |
| 方法 | duplicate_task |
func duplicate_task() -> GFDownloadTask: |
| 方法 | to_dict |
func to_dict() -> Dictionary: |
| 方法 | get_status_name |
static func get_status_name(value: Status) -> String: |
枚举¶
Status¶
- API:
public
enum Status { ## 已加入队列。 QUEUED, ## 正在下载。 RUNNING, ## 已暂停,等待恢复。 PAUSED, ## 已完成。 COMPLETED, ## 已失败。 FAILED, ## 已取消。 CANCELLED, }
下载任务状态。
属性¶
task_id¶
- API:
public
任务句柄。
url¶
- API:
public
下载 URL。
target_path¶
- API:
public
最终写入路径。
temp_path¶
- API:
public
临时文件路径。
segment_path¶
- API:
public
分段续传文件路径。
headers¶
- API:
public
HTTP 请求头。
expected_sha256¶
- API:
public
期望 SHA-256 校验值。为空时不校验。
resume¶
- API:
public
是否允许从临时文件续传。
overwrite¶
- API:
public
目标文件已存在时是否覆盖。
max_retries¶
- API:
public
最大重试次数。
retry_count¶
- API:
public
已执行重试次数。
retry_delay_seconds¶
- API:
public
每次重试前等待的秒数。
retry_not_before_msec¶
- API:
public
下次可重试的时间戳,单位毫秒。
metadata¶
- API:
public
项目层可附加的任务元数据。
结构:
metadata: Dictionary,复制到下载任务中的项目侧元数据。
status¶
- API:
public
当前任务状态。
received_bytes¶
- API:
public
已接收字节数。
total_bytes¶
- API:
public
总字节数;未知时为 -1。
response_code¶
- API:
public
最近一次 HTTP 响应码。
error¶
- API:
public
失败或取消原因。
方法¶
duplicate_task¶
- API:
public
创建同内容拷贝。
返回:新任务。
to_dict¶
- API:
public
导出任务状态字典。
返回:任务字典。
结构:
return: Dictionary,包含任务标识、路径、请求头、重试设置、metadata、状态、字节计数、响应码和错误信息。
get_status_name¶
- API:
public
获取任务状态名称。
参数:
| 名称 | 说明 |
|---|---|
value |
任务状态。 |
返回:状态名称。