-
Notifications
You must be signed in to change notification settings - Fork 0
fetch download.Class.DownloadQueue
@zenstone/ts-utils / fetch-download / DownloadQueue
Defined in: src/fetch-download/DownloadQueue.ts:31
new DownloadQueue(
tasks):DownloadQueue
Defined in: src/fetch-download/DownloadQueue.ts:84
创建 DownloadQueue 实例,允许多种 input 类型
// DownloadTask
const task1 = new DownloadQueue([new DownloadTask('url')]);
const task2 = new DownloadQueue([fetchDownload('url')]);
// URL 输入
const task3 = new DownloadQueue(['url']);
const task4 = new DownloadQueue([new URL('url')]);
// Request or DownloadRequest 结构
const task5 = new DownloadQueue([new Request('url')]);
const task6 = new DownloadQueue([{ url: 'url' }]);
// Promise<Response>
const abort = new AbortController();
const task7 = new DownloadQueue([
fetch('url', { signal: abort.signal }),
]);
// Response
const task8 = new DownloadTask([
await fetch('url'),
]);DownloadQueue
get completeTs():
number
Defined in: src/fetch-download/DownloadQueue.ts:194
read 完成时间戳(所有下载任务都完成)
- 如果下载未开始,返回 0
- 如果下载已开始,但并未下载完成,则会返回当前时间的时间戳
number
get contentLength():
number
Defined in: src/fetch-download/DownloadQueue.ts:133
所有下载任务的 Content-Length 总和
number
get elapsedMs():
number
Defined in: src/fetch-download/DownloadQueue.ts:208
read 数据经过多少时间(毫秒,所有下载任务都完成)
如果为实际完成,则返回当前时间的时间戳
如果未开始,则返回 0
number
get error():
unknown
Defined in: src/fetch-download/DownloadQueue.ts:184
获取错误信息
unknown
get id():
string
Defined in: src/fetch-download/DownloadQueue.ts:94
DownloadQueue Id
string
get isReaded():
boolean
Defined in: src/fetch-download/DownloadQueue.ts:177
是否已经 read 完毕
boolean
get isStarted():
boolean
Defined in: src/fetch-download/DownloadQueue.ts:170
是否开始 read
boolean
get percent():
number
Defined in: src/fetch-download/DownloadQueue.ts:163
所有下载任务的接收 Response body 进度百分比(0 - 100)
number
get progress():
number
Defined in: src/fetch-download/DownloadQueue.ts:151
所有下载任务的接收 Response body 进度小数(0 - 1)
number
get received():
number
Defined in: src/fetch-download/DownloadQueue.ts:142
所有下载任务的已接收 Response body 大小
number
get size():
number
Defined in: src/fetch-download/DownloadQueue.ts:124
所有下载任务的实际总大小
number
get speed():
number
Defined in: src/fetch-download/DownloadQueue.ts:226
接收速度(所有下载任务的平均值),单位为字节/秒,需要自行转换
如果未开始,返回 0
import { filesize } from 'filesize';
const task = await fetchDownload().read();
console.log(`${filesize(task.speed, { bits: true })}/s`); // kbit/s
console.log(`${filesize(task.speed)}/s`); // KB/snumber
get state():
DownloadTaskState
Defined in: src/fetch-download/DownloadQueue.ts:117
当前状态 DownloadTaskState
注意 DownloadQueue 不应该出现 fetching 状态
get tasks():
DownloadTask[]
Defined in: src/fetch-download/DownloadQueue.ts:101
所有下载任务
get tasksCount():
number
Defined in: src/fetch-download/DownloadQueue.ts:108
所有下载任务的总数
number
protected_initTasksQueue(opts?):Promise<DownloadTask>[]
Defined in: src/fetch-download/DownloadQueue.ts:233
Promise<DownloadTask>[]
newErr(
msg):DownloadQueueError
Defined in: src/fetch-download/DownloadQueue.ts:305
string
read(
opts?):Promise<DownloadQueue>
Defined in: src/fetch-download/DownloadQueue.ts:265
Queue 读取方法(调用每一个 task 的 read)
-
onFetch、onHeaders、onProgress、onComplete、onError保留对应每一个 task 的事件 -
onFinish对应 Queue 全部 tasks 读取完毕 -
onQueueError对应 Queue 任意一个 task 读取过程中出错
DownloadQueueProcessCallback | DownloadQueueProcessOptions
Promise<DownloadQueue>
reduce<
T>(fn,initValue):T
Defined in: src/fetch-download/DownloadQueue.ts:253
T
(acc, it) => T
T
T