7.0.2 • Published 6 months ago

@capgo/capacitor-downloader v7.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

@capgo/capacitor-downloader

Download file in background or foreground

WIP: the plugin is not yet ready for production

Install

npm install @capgo/capacitor-downloader
npx cap sync

API

download(...)

download(options: DownloadOptions) => Promise<DownloadTask>
ParamType
optionsDownloadOptions

Returns: Promise<DownloadTask>


pause(...)

pause(id: string) => Promise<void>
ParamType
idstring

resume(...)

resume(id: string) => Promise<void>
ParamType
idstring

stop(...)

stop(id: string) => Promise<void>
ParamType
idstring

checkStatus(...)

checkStatus(id: string) => Promise<DownloadTask>
ParamType
idstring

Returns: Promise<DownloadTask>


getFileInfo(...)

getFileInfo(path: string) => Promise<{ size: number; type: string; }>
ParamType
pathstring

Returns: Promise<{ size: number; type: string; }>


addListener('downloadProgress', ...)

addListener(eventName: 'downloadProgress', listenerFunc: (progress: { id: string; progress: number; }) => void) => Promise<PluginListenerHandle>
ParamType
eventName'downloadProgress'
listenerFunc(progress: { id: string; progress: number; }) => void

Returns: Promise<PluginListenerHandle>


addListener('downloadCompleted', ...)

addListener(eventName: 'downloadCompleted', listenerFunc: (result: { id: string; }) => void) => Promise<PluginListenerHandle>
ParamType
eventName'downloadCompleted'
listenerFunc(result: { id: string; }) => void

Returns: Promise<PluginListenerHandle>


addListener('downloadFailed', ...)

addListener(eventName: 'downloadFailed', listenerFunc: (error: { id: string; error: string; }) => void) => Promise<PluginListenerHandle>
ParamType
eventName'downloadFailed'
listenerFunc(error: { id: string; error: string; }) => void

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Interfaces

DownloadTask

PropType
idstring
progressnumber
state'PENDING' | 'RUNNING' | 'PAUSED' | 'DONE' | 'ERROR'

DownloadOptions

PropType
idstring
urlstring
destinationstring
headers{ key: string: string; }
network'cellular' | 'wifi-only'
priority'high' | 'normal' | 'low'

PluginListenerHandle

PropType
remove() => Promise<void>

Credit

This plugin was inspired from: https://github.com/kesha-antonov/react-native-background-downloader