跳过内容

开始使用

终端窗口
bun add @capgo/capacitor-downloader
bunx cap sync

导入

导入
import { CapacitorDownloader } from '@capgo/capacitor-downloader';

API概述

API概述

download

下载

开始一个新的下载任务

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
const task = await Downloader.download({
id: 'my-download',
url: 'https://example.com/file.pdf',
destination: 'downloads/file.pdf'
});

pause

暂停

暂停一个正在下载的任务。 下载可以从同一位置恢复。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.pause({} as { id: string });

恢复暂停下载。 从上次暂停处继续下载。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.resume({} as { id: string });

停止并永久取消下载。 下载的数据将被删除。

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.stop({} as { id: string });

checkStatus

下载状态

复制到剪贴板

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.checkStatus({} as { id: string });

protectedTokens

import { CapacitorDownloader } from '@capgo/capacitor-downloader';
await CapacitorDownloader.getFileInfo({} as { path: string });

类型参考

类型参考

DownloadOptions

下载选项

下载时的配置选项

export interface DownloadOptions {
/** Unique identifier for this download task */
id: string;
/** URL of the file to download */
url: string;
/** Local file path where the download will be saved */
destination: string;
/** Optional HTTP headers to include in the request */
headers?: { [key: string]: string };
/** Network type requirement for download */
network?: 'cellular' | 'wifi-only';
/** Download priority level */
priority?: 'high' | 'normal' | 'low';
}

DownloadTask

下载任务

下载任务的当前状态和进度

export interface DownloadTask {
/** Unique identifier for the download task */
id: string;
/** Download progress from 0 to 100 */
progress: number;
/** Current state of the download */
state: 'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR';
}

真实来源

真实来源

本页面由插件生成 src/definitions.ts当公共 API 上游发生变化时,请重新同步