forked from EkoLabs/react-native-background-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
125 lines (104 loc) · 3.2 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Type definitions for @kesha-antonov/react-native-background-downloader 2.6
// Project: https://github.com/kesha-antonov/react-native-background-downloader
// Definitions by: Philip Su <https://github.com/fivecar>,
// Adam Hunter <https://github.com/adamrhunter>,
// Junseong Park <https://github.com/Kweiza>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface DownloadHeaders {
[key: string]: string | null;
}
type SetHeaders = (h: DownloadHeaders) => void;
export interface TaskInfoObject {
id: string;
metadata: object | string;
percent?: number;
bytesWritten?: number;
totalBytes?: number;
beginHandler?: Function;
progressHandler?: Function;
doneHandler?: Function;
errorHandler?: Function;
}
export type TaskInfo = TaskInfoObject;
export interface BeginHandlerObject {
expectedBytes: number;
headers: { [key: string]: string };
}
export type BeginHandler = ({
expectedBytes,
headers,
}: BeginHandlerObject) => any;
export type ProgressHandler = (
percent: number,
bytesWritten: number,
totalBytes: number
) => any;
export type DoneHandler = () => any;
export type ErrorHandler = (error: any, errorCode: any) => any;
export type DownloadTaskState =
| "DOWNLOADING"
| "PAUSED"
| "DONE"
| "FAILED"
| "STOPPED";
export interface DownloadTask {
constructor: (taskInfo: TaskInfo) => DownloadTask;
id: string;
state: DownloadTaskState;
percent: number;
bytesWritten: number;
totalBytes: number;
begin: (handler: BeginHandler) => DownloadTask;
progress: (handler: ProgressHandler) => DownloadTask;
done: (handler: DoneHandler) => DownloadTask;
error: (handler: ErrorHandler) => DownloadTask;
_beginHandler: BeginHandler;
_progressHandler: ProgressHandler;
_doneHandler: DoneHandler;
_errorHandler: ErrorHandler;
pause: () => any;
resume: () => any;
stop: () => any;
}
export type CheckForExistingDownloads = () => Promise<DownloadTask[]>;
export type EnsureDownloadsAreRunning = () => Promise<void>;
export interface DownloadOption {
id: string;
url: string;
destination: string;
headers?: DownloadHeaders | undefined;
}
export type Download = (options: DownloadOption) => DownloadTask;
export type CompleteHandler = (id: string) => void;
export interface Directories {
documents: string;
}
export interface Network {
WIFI_ONLY: string;
ALL: string;
}
export interface Priority {
HIGH: string;
MEDIUM: string;
LOW: string;
}
export const setHeaders: SetHeaders;
export const checkForExistingDownloads: CheckForExistingDownloads;
export const ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
export const download: Download;
export const completeHandler: CompleteHandler;
export const directories: Directories;
export const Network: Network;
export const Priority: Priority;
export interface RNBackgroundDownloader {
setHeaders: SetHeaders;
checkForExistingDownloads: CheckForExistingDownloads;
ensureDownloadsAreRunning: EnsureDownloadsAreRunning;
download: Download;
completeHandler: CompleteHandler;
directories: Directories;
Network: Network;
Priority: Priority;
}
declare const RNBackgroundDownloader: RNBackgroundDownloader;
export default RNBackgroundDownloader;