Skip to content

Commit 4740be4

Browse files
authored
Merge pull request wkh237#256 from alpha0010/patch-1
Add flow type definitions
2 parents b94e9ff + 39c0c0f commit 4740be4

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed

index.js.flow

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
// @flow strict
2+
3+
declare class AndroidApi {
4+
actionViewIntent(path: string, mime?: string): Promise<void>;
5+
addCompleteDownload(options: AndroidDownloadOption): Promise<void>;
6+
getContentIntent(mime: string): Promise<string>;
7+
getSDCardApplicationDir(): Promise<string>;
8+
getSDCardDir(): Promise<string>;
9+
}
10+
11+
declare class FetchBlobResponse {
12+
data: string;
13+
respInfo: RNFetchBlobResponseInfo;
14+
taskId: string;
15+
type: "utf8" | "base64" | "path";
16+
array(): Promise<number[]>;
17+
base64(): string | Promise<string>;
18+
blob(): Promise<Blob>;
19+
flush(): Promise<void>;
20+
info(): RNFetchBlobResponseInfo;
21+
// $FlowExpectedError Not possible to specify in strict mode.
22+
json(): any;
23+
path(): string;
24+
readFile(encoding: Encoding): ?Promise<number[] | string>;
25+
readStream(encoding: Encoding): ?Promise<RNFetchBlobReadStream>;
26+
session(name: string): ?RNFetchBlobSession;
27+
text(): string | Promise<string>;
28+
}
29+
30+
declare class FsApi {
31+
RNFetchBlobSession: RNFetchBlobSession;
32+
dirs: Dirs;
33+
appendFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
34+
asset(path: string): string;
35+
cp(path: string, dest: string): Promise<boolean>;
36+
createFile(path: string, data: string, encoding: Encoding | "uri"): Promise<string>;
37+
df(): Promise<AndroidFsStat | IosFsStat>;
38+
exists(path: string): Promise<boolean>;
39+
hash(path: string, algorithm: HashAlgorithm): Promise<string>;
40+
isDir(path: string): Promise<boolean>;
41+
ls(path: string): Promise<string[]>;
42+
lstat(path: string): Promise<RNFetchBlobStat[]>;
43+
mkdir(path: string): Promise<boolean>;
44+
mv(path: string, dest: string): Promise<boolean>;
45+
pathForAppGroup(groupName: string): Promise<string>;
46+
readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<number[] | string>;
47+
readStream(path: string, encoding: Encoding, bufferSize?: number, tick?: number): Promise<RNFetchBlobReadStream>;
48+
scanFile(pairs: {mime: string, path: string}[]): Promise<void>;
49+
session(name: string): RNFetchBlobSession;
50+
slice(src: string, dest: string, start: number, end: number): Promise<string>;
51+
stat(path: string): Promise<RNFetchBlobStat>;
52+
unlink(path: string): Promise<void>;
53+
writeFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
54+
writeStream(path: string, encoding: Encoding, append?: boolean): Promise<RNFetchBlobWriteStream>;
55+
}
56+
57+
declare class IosApi {
58+
excludeFromBackupKey(path: string): Promise<void>;
59+
openDocument(path: string, scheme?: string): Promise<void>;
60+
previewDocument(path: string, scheme?: string): Promise<void>;
61+
}
62+
63+
declare class RNFetchBlobReadStream {
64+
bufferSize?: number;
65+
closed: boolean;
66+
encoding: Encoding;
67+
path: string;
68+
tick: number;
69+
onData(fn: (chunk: string) => void): void;
70+
onEnd(fn: () => void): void;
71+
onError(fn: (err: Error) => void): void;
72+
open(): void;
73+
}
74+
75+
declare class RNFetchBlobSession {
76+
static getSession(name: string): RNFetchBlobSession;
77+
static removeSession(name: string): void;
78+
static setSession(name: string, val: RNFetchBlobSession): void;
79+
80+
name: string;
81+
add(path: string): RNFetchBlobSession;
82+
constructor(name: string, list: string[]): RNFetchBlobSession;
83+
dispose(): Promise<void>;
84+
list(): string[];
85+
remove(path: string): RNFetchBlobSession;
86+
}
87+
88+
declare class RNFetchBlobWriteStream {
89+
append: boolean;
90+
encoding: string;
91+
id: string;
92+
close(): void;
93+
write(data: string): Promise<void>;
94+
}
95+
96+
declare class RNFetchBlob {
97+
android: AndroidApi;
98+
base64: {+decode: (input: string) => string, +encode: (input: string) => string};
99+
fs: FsApi;
100+
ios: IosApi;
101+
config(options: RNFetchBlobConfig): {fetch: (method: Methods, url: string, headers?: {[key: string]: string}, body?: string | FormField[]) => StatefulPromise<FetchBlobResponse>};
102+
fetch(method: Methods, url: string, headers?: {[key: string]: string}, body?: string | FormField[]): StatefulPromise<FetchBlobResponse>;
103+
session(name: string): RNFetchBlobSession;
104+
wrap(path: string): string;
105+
}
106+
107+
declare class StatefulPromise<T> extends Promise<T> {
108+
cancel(callback?: (error: ?string, taskId: ?string) => void): void;
109+
expire(callback: () => void): StatefulPromise<void>;
110+
progress(config: {count?: number, interval?: number} | ProgressCallback, callback?: ProgressCallback): StatefulPromise<T>;
111+
stateChange(callback: (state: RNFetchBlobResponseInfo) => void): StatefulPromise<T>;
112+
uploadProgress(config: {count?: number, interval?: number} | UploadProgressCallback, callback?: UploadProgressCallback): StatefulPromise<T>;
113+
}
114+
115+
export type AddAndroidDownloads = {
116+
description?: string,
117+
mediaScannable?: boolean,
118+
mime?: string,
119+
notification?: boolean,
120+
path?: string,
121+
title?: string,
122+
useDownloadManager?: boolean
123+
};
124+
export type AndroidDownloadOption = {
125+
description?: string,
126+
mime?: string,
127+
path: string,
128+
showNotification?: boolean,
129+
title?: string
130+
};
131+
export type AndroidFsStat = {
132+
external_free: number,
133+
external_total: number,
134+
internal_free: number,
135+
internal_total: number
136+
};
137+
export type Dirs = {
138+
CacheDir: string,
139+
DCIMDir: string,
140+
DocumentDir: string,
141+
DownloadDir: string,
142+
LibraryDir: string,
143+
MainBundleDir: string,
144+
MovieDir: string,
145+
MusicDir: string,
146+
PictureDir: string,
147+
SDCardApplicationDir: string,
148+
SDCardDir: string
149+
};
150+
export type Encoding = "utf8" | "ascii" | "base64";
151+
export type FormField = {data: string, filename?: string, name: string, type?: string};
152+
export type HashAlgorithm = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
153+
export type IosFsStat = {free: number, total: number};
154+
export type Methods = "POST" | "GET" | "DELETE" | "PUT" | "post" | "get" | "delete" | "put";
155+
export type ProgressCallback = (received: number, total: number) => void;
156+
export type RNFetchBlobConfig = {
157+
IOSBackgroundTask?: boolean,
158+
addAndroidDownloads?: AddAndroidDownloads,
159+
appendExt?: string,
160+
fileCache?: boolean,
161+
indicator?: boolean,
162+
overwrite?: boolean,
163+
path?: string,
164+
session?: string,
165+
timeout?: number,
166+
trusty?: boolean
167+
};
168+
export type RNFetchBlobResponseInfo = {
169+
headers: {[fieldName: string]: string},
170+
redirects: string[],
171+
respType: "text" | "blob" | "" | "json",
172+
rnfbEncode: "path" | Encoding,
173+
state: string,
174+
status: number,
175+
taskId: string,
176+
timeout: boolean
177+
};
178+
export type RNFetchBlobStat = {
179+
filename: string,
180+
lastModified: number,
181+
path: string,
182+
size: number,
183+
type: "directory" | "file" | "asset"
184+
};
185+
export type UploadProgressCallback = (sent: number, total: number) => void;
186+
187+
declare export default RNFetchBlob;

0 commit comments

Comments
 (0)