react-native-ota-hot-update 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +20 -8
  3. package/android/build.gradle +32 -4
  4. package/android/generated/java/com/otahotupdate/NativeOtaHotUpdateSpec.java +54 -0
  5. package/android/generated/jni/CMakeLists.txt +36 -0
  6. package/android/generated/jni/RNOtaHotUpdateSpec-generated.cpp +56 -0
  7. package/android/generated/jni/RNOtaHotUpdateSpec.h +31 -0
  8. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ComponentDescriptors.cpp +22 -0
  9. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ComponentDescriptors.h +24 -0
  10. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/EventEmitters.cpp +16 -0
  11. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/EventEmitters.h +17 -0
  12. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/Props.cpp +19 -0
  13. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/Props.h +18 -0
  14. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/RNOtaHotUpdateSpecJSI-generated.cpp +56 -0
  15. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/RNOtaHotUpdateSpecJSI.h +103 -0
  16. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ShadowNodes.cpp +17 -0
  17. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ShadowNodes.h +23 -0
  18. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/States.cpp +16 -0
  19. package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/States.h +19 -0
  20. package/android/gradle.properties +5 -5
  21. package/android/src/main/AndroidManifest.xml +1 -1
  22. package/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +57 -0
  23. package/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +142 -0
  24. package/android/src/newarch/OtaHotUpdateSpec.kt +7 -0
  25. package/android/src/oldarch/OtaHotUpdateSpec.kt +15 -0
  26. package/ios/OtaHotUpdate.h +13 -0
  27. package/ios/{RNhotupdate.m → OtaHotUpdate.mm} +50 -33
  28. package/ios/generated/RNOtaHotUpdateSpec/ComponentDescriptors.cpp +22 -0
  29. package/ios/generated/RNOtaHotUpdateSpec/ComponentDescriptors.h +24 -0
  30. package/ios/generated/RNOtaHotUpdateSpec/EventEmitters.cpp +16 -0
  31. package/ios/generated/RNOtaHotUpdateSpec/EventEmitters.h +17 -0
  32. package/ios/generated/RNOtaHotUpdateSpec/Props.cpp +19 -0
  33. package/ios/generated/RNOtaHotUpdateSpec/Props.h +18 -0
  34. package/ios/generated/RNOtaHotUpdateSpec/RCTComponentViewHelpers.h +18 -0
  35. package/ios/generated/RNOtaHotUpdateSpec/RNOtaHotUpdateSpec-generated.mm +67 -0
  36. package/ios/generated/RNOtaHotUpdateSpec/RNOtaHotUpdateSpec.h +72 -0
  37. package/ios/generated/RNOtaHotUpdateSpec/ShadowNodes.cpp +17 -0
  38. package/ios/generated/RNOtaHotUpdateSpec/ShadowNodes.h +23 -0
  39. package/ios/generated/RNOtaHotUpdateSpec/States.cpp +16 -0
  40. package/ios/generated/RNOtaHotUpdateSpec/States.h +19 -0
  41. package/ios/generated/RNOtaHotUpdateSpecJSI-generated.cpp +56 -0
  42. package/ios/generated/RNOtaHotUpdateSpecJSI.h +103 -0
  43. package/lib/commonjs/NativeOtaHotUpdate.js +9 -0
  44. package/lib/commonjs/NativeOtaHotUpdate.js.map +1 -0
  45. package/lib/commonjs/download.d.js +2 -0
  46. package/lib/commonjs/download.d.js.map +1 -0
  47. package/lib/commonjs/index.js +113 -0
  48. package/lib/commonjs/index.js.map +1 -0
  49. package/lib/module/NativeOtaHotUpdate.js +5 -0
  50. package/lib/module/NativeOtaHotUpdate.js.map +1 -0
  51. package/lib/module/download.d.js +2 -0
  52. package/lib/module/download.d.js.map +1 -0
  53. package/lib/module/index.js +109 -0
  54. package/lib/module/index.js.map +1 -0
  55. package/lib/typescript/commonjs/package.json +1 -0
  56. package/lib/typescript/commonjs/src/NativeOtaHotUpdate.d.ts +11 -0
  57. package/lib/typescript/commonjs/src/NativeOtaHotUpdate.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/index.d.ts +25 -0
  59. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  60. package/lib/typescript/module/package.json +1 -0
  61. package/lib/typescript/module/src/NativeOtaHotUpdate.d.ts +11 -0
  62. package/lib/typescript/module/src/NativeOtaHotUpdate.d.ts.map +1 -0
  63. package/lib/typescript/module/src/index.d.ts +25 -0
  64. package/lib/typescript/module/src/index.d.ts.map +1 -0
  65. package/package.json +184 -12
  66. package/{rn-hotupdate.podspec → react-native-ota-hot-update.podspec} +3 -3
  67. package/react-native.config.js +10 -6
  68. package/src/NativeOtaHotUpdate.ts +12 -0
  69. package/src/download.d.ts +759 -689
  70. package/src/index.tsx +67 -40
  71. package/android/src/main/java/com/rnhotupdate/HotUpdateModule.java +0 -161
  72. package/android/src/main/java/com/rnhotupdate/OtaHotUpdate.java +0 -45
  73. package/ios/RNhotupdate.h +0 -12
  74. package/ios/RNhotupdate.xcodeproj/project.pbxproj +0 -281
  75. package/ios/RNhotupdate.xcworkspace/contents.xcworkspacedata +0 -7
  76. /package/android/src/main/java/com/{rnhotupdate → otahotupdate}/SharedPrefs.kt +0 -0
package/src/download.d.ts CHANGED
@@ -1,860 +1,930 @@
1
-
2
1
  interface DownloadManager {
3
- fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any | null): StatefulPromise<FetchBlobResponse>;
2
+ fetch(
3
+ method: Methods,
4
+ url: string,
5
+ headers?: { [key: string]: string },
6
+ body?: any | null
7
+ ): StatefulPromise<FetchBlobResponse>;
4
8
 
5
- base64: { encode(input: string): string; decode(input: string): string };
6
- android: AndroidApi;
7
- ios: IOSApi;
9
+ base64: { encode(input: string): string; decode(input: string): string };
10
+ android: AndroidApi;
11
+ ios: IOSApi;
8
12
 
9
- config(options: ReactNativeBlobUtilConfig): DownloadManager;
13
+ config(options: ReactNativeBlobUtilConfig): DownloadManager;
10
14
 
11
- session(name: string): ReactNativeBlobUtilSession;
15
+ session(name: string): ReactNativeBlobUtilSession;
12
16
 
13
- fs: FS;
14
- MediaCollection: MediaCollection;
17
+ fs: FS;
18
+ MediaCollection: MediaCollection;
15
19
 
16
- wrap(path: string): string;
20
+ wrap(path: string): string;
17
21
 
18
- net: Net;
19
- polyfill: Polyfill;
20
- // this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
21
- JSONStream: any;
22
+ net: Net;
23
+ polyfill: Polyfill;
24
+ // this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
25
+ JSONStream: any;
22
26
  }
23
27
 
24
28
  export interface Polyfill {
25
- Blob: PolyfillBlob;
26
- File: PolyfillFile;
27
- XMLHttpRequest: PolyfillXMLHttpRequest;
28
- ProgressEvent: PolyfillProgressEvent;
29
- Event: PolyfillEvent;
30
- FileReader: PolyfillFileReader;
31
- Fetch: PolyfillFetch;
29
+ Blob: PolyfillBlob;
30
+ File: PolyfillFile;
31
+ XMLHttpRequest: PolyfillXMLHttpRequest;
32
+ ProgressEvent: PolyfillProgressEvent;
33
+ Event: PolyfillEvent;
34
+ FileReader: PolyfillFileReader;
35
+ Fetch: PolyfillFetch;
32
36
  }
33
37
 
34
38
  export declare class PolyfillFetch extends ReactNativeBlobUtilFetchPolyfill {
35
- constructor(config: ReactNativeBlobUtilConfig);
39
+ constructor(config: ReactNativeBlobUtilConfig);
36
40
  }
37
41
 
38
42
  export declare class ReactNativeBlobUtilFetchPolyfill {
39
- constructor(config: ReactNativeBlobUtilConfig);
43
+ constructor(config: ReactNativeBlobUtilConfig);
40
44
 
41
- build(): (url: string, options: ReactNativeBlobUtilConfig) => StatefulPromise<ReactNativeBlobUtilFetchRepsonse>;
45
+ build(): (
46
+ url: string,
47
+ options: ReactNativeBlobUtilConfig
48
+ ) => StatefulPromise<ReactNativeBlobUtilFetchRepsonse>;
42
49
  }
43
50
 
44
51
  export interface ReactNativeBlobUtilFetchRepsonse {
45
- arrayBuffer(): Promise<any[]>;
52
+ arrayBuffer(): Promise<any[]>;
46
53
 
47
- blob(): Promise<PolyfillBlob>;
54
+ blob(): Promise<PolyfillBlob>;
48
55
 
49
- json(): Promise<any>;
56
+ json(): Promise<any>;
50
57
 
51
- rawResp(): Promise<FetchBlobResponse>;
58
+ rawResp(): Promise<FetchBlobResponse>;
52
59
 
53
- text(): Promise<string>;
60
+ text(): Promise<string>;
54
61
 
55
- bodyUsed: boolean;
56
- headers: any;
57
- ok: boolean;
58
- resp: FetchBlobResponse;
59
- rnfbResp: FetchBlobResponse;
60
- rnfbRespInfo: ReactNativeBlobUtilResponseInfo;
61
- status: number;
62
- type: string;
62
+ bodyUsed: boolean;
63
+ headers: any;
64
+ ok: boolean;
65
+ resp: FetchBlobResponse;
66
+ rnfbResp: FetchBlobResponse;
67
+ rnfbRespInfo: ReactNativeBlobUtilResponseInfo;
68
+ status: number;
69
+ type: string;
63
70
  }
64
71
 
65
72
  /**
66
73
  * ReactNativeBlobUtil response object class.
67
74
  */
68
75
  export interface FetchBlobResponse {
69
- taskId: string;
70
-
71
- /**
72
- * get path of response temp file
73
- * @return File path of temp file.
74
- */
75
- path(): string;
76
-
77
- type: "base64" | "path" | "utf8";
78
- data: any;
79
-
80
- /**
81
- * Convert result to javascript ReactNativeBlobUtil object.
82
- * @return Return a promise resolves Blob object.
83
- */
84
- blob(contentType: string, sliceSize: number): Promise<PolyfillBlob>;
85
-
86
- /**
87
- * Convert result to text.
88
- * @return Decoded base64 string.
89
- */
90
- text(): string | Promise<any>;
91
-
92
- /**
93
- * Convert result to JSON object.
94
- * @return Parsed javascript object.
95
- */
96
- json(): any;
97
-
98
- /**
99
- * Return BASE64 string directly.
100
- * @return BASE64 string of response body.
101
- */
102
- base64(): any;
103
-
104
- /**
105
- * Remove cahced file
106
- */
107
- flush(): void;
108
-
109
- respInfo: ReactNativeBlobUtilResponseInfo;
110
-
111
- info(): ReactNativeBlobUtilResponseInfo;
112
-
113
- session(name: string): ReactNativeBlobUtilSession | null;
114
-
115
- /**
116
- * Read file content with given encoding, if the response does not contains
117
- * a file path, show warning message
118
- * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
119
- */
120
- readFile(encode: Encoding): Promise<any> | null;
121
-
122
- /**
123
- * Start read stream from cached file
124
- * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
125
- */
126
- readStream(encode: Encoding): ReactNativeBlobUtilStream | null;
76
+ taskId: string;
77
+
78
+ /**
79
+ * get path of response temp file
80
+ * @return File path of temp file.
81
+ */
82
+ path(): string;
83
+
84
+ type: 'base64' | 'path' | 'utf8';
85
+ data: any;
86
+
87
+ /**
88
+ * Convert result to javascript ReactNativeBlobUtil object.
89
+ * @return Return a promise resolves Blob object.
90
+ */
91
+ blob(contentType: string, sliceSize: number): Promise<PolyfillBlob>;
92
+
93
+ /**
94
+ * Convert result to text.
95
+ * @return Decoded base64 string.
96
+ */
97
+ text(): string | Promise<any>;
98
+
99
+ /**
100
+ * Convert result to JSON object.
101
+ * @return Parsed javascript object.
102
+ */
103
+ json(): any;
104
+
105
+ /**
106
+ * Return BASE64 string directly.
107
+ * @return BASE64 string of response body.
108
+ */
109
+ base64(): any;
110
+
111
+ /**
112
+ * Remove cahced file
113
+ */
114
+ flush(): void;
115
+
116
+ respInfo: ReactNativeBlobUtilResponseInfo;
117
+
118
+ info(): ReactNativeBlobUtilResponseInfo;
119
+
120
+ session(name: string): ReactNativeBlobUtilSession | null;
121
+
122
+ /**
123
+ * Read file content with given encoding, if the response does not contains
124
+ * a file path, show warning message
125
+ * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
126
+ */
127
+ readFile(encode: Encoding): Promise<any> | null;
128
+
129
+ /**
130
+ * Start read stream from cached file
131
+ * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
132
+ */
133
+ readStream(encode: Encoding): ReactNativeBlobUtilStream | null;
127
134
  }
128
135
 
129
136
  export interface PolyfillFileReader extends EventTarget {
130
- isRNFBPolyFill: boolean;
137
+ isRNFBPolyFill: boolean;
131
138
 
132
- onloadstart(e: Event): void;
139
+ onloadstart(e: Event): void;
133
140
 
134
- onprogress(e: Event): void;
141
+ onprogress(e: Event): void;
135
142
 
136
- onload(e: Event): void;
143
+ onload(e: Event): void;
137
144
 
138
- onabort(e: Event): void;
145
+ onabort(e: Event): void;
139
146
 
140
- onerror(e: Event): void;
147
+ onerror(e: Event): void;
141
148
 
142
- onloadend(e: Event): void;
149
+ onloadend(e: Event): void;
143
150
 
144
- abort(): void;
151
+ abort(): void;
145
152
 
146
- readAsArrayBuffer(b: PolyfillBlob): void;
153
+ readAsArrayBuffer(b: PolyfillBlob): void;
147
154
 
148
- readAsBinaryString(b: PolyfillBlob): void;
155
+ readAsBinaryString(b: PolyfillBlob): void;
149
156
 
150
- readAsText(b: PolyfillBlob, label?: string): void;
157
+ readAsText(b: PolyfillBlob, label?: string): void;
151
158
 
152
- readAsDataURL(b: PolyfillBlob): void;
159
+ readAsDataURL(b: PolyfillBlob): void;
153
160
 
154
- readyState: number;
155
- result: number;
161
+ readyState: number;
162
+ result: number;
156
163
  }
157
164
 
158
165
  export declare namespace PolyfillFileReader {
159
- const EMPTY: number;
160
- const LOADING: number;
161
- const DONE: number;
166
+ const EMPTY: number;
167
+ const LOADING: number;
168
+ const DONE: number;
162
169
  }
163
170
 
164
171
  export declare class PolyfillEvent {}
165
172
 
166
173
  export interface PolyfillProgressEvent extends EventTarget {
167
- lengthComputable: boolean;
168
- loaded: number;
169
- total: number;
174
+ lengthComputable: boolean;
175
+ loaded: number;
176
+ total: number;
170
177
  }
171
178
 
172
179
  export declare class PolyfillBlob implements EventTarget {
173
- /**
174
- * ReactNativeBlobUtil Blob polyfill, create a Blob directly from file path, BASE64
175
- * encoded data, and string. The conversion is done implicitly according to
176
- * given `mime`. However, the blob creation is asynchronously, to register
177
- * event `onCreated` is need to ensure the Blob is creadted.
178
- *
179
- * @param data Content of Blob object
180
- * @param cType Content type settings of Blob object, `text/plain` by default
181
- * @param defer When this argument set to `true`, blob constructor will not invoke blob created event automatically.
182
- */
183
- constructor(data: any, cType: any, defer: boolean);
184
-
185
- /**
186
- * Since Blob content will asynchronously write to a file during creation,
187
- * use this method to register an event handler for Blob initialized event.
188
- * @param fn An event handler invoked when Blob created
189
- * @return The Blob object instance itself
190
- */
191
- onCreated(fn: () => void): PolyfillBlob;
192
-
193
- markAsDerived(): void;
194
-
195
- /**
196
- * Get file reference of the Blob object.
197
- * @return Blob file reference which can be consumed by ReactNativeBlobUtil fs
198
- */
199
- getReactNativeBlobUtilRef(): string;
200
-
201
- /**
202
- * Create a Blob object which is sliced from current object
203
- * @param start Start byte number
204
- * @param end End byte number
205
- * @param contentType Optional, content type of new Blob object
206
- */
207
- slice(start?: number, end?: number, contentType?: string): PolyfillBlob;
208
-
209
- /**
210
- * Read data of the Blob object, this is not standard method.
211
- * @param encoding Read data with encoding
212
- */
213
- readBlob(encoding: string): Promise<any>;
214
-
215
- /**
216
- * Release the resource of the Blob object.
217
- * @nonstandard
218
- */
219
- close(): Promise<void>;
180
+ /**
181
+ * ReactNativeBlobUtil Blob polyfill, create a Blob directly from file path, BASE64
182
+ * encoded data, and string. The conversion is done implicitly according to
183
+ * given `mime`. However, the blob creation is asynchronously, to register
184
+ * event `onCreated` is need to ensure the Blob is creadted.
185
+ *
186
+ * @param data Content of Blob object
187
+ * @param cType Content type settings of Blob object, `text/plain` by default
188
+ * @param defer When this argument set to `true`, blob constructor will not invoke blob created event automatically.
189
+ */
190
+ constructor(data: any, cType: any, defer: boolean);
191
+
192
+ /**
193
+ * Since Blob content will asynchronously write to a file during creation,
194
+ * use this method to register an event handler for Blob initialized event.
195
+ * @param fn An event handler invoked when Blob created
196
+ * @return The Blob object instance itself
197
+ */
198
+ onCreated(fn: () => void): PolyfillBlob;
199
+
200
+ markAsDerived(): void;
201
+
202
+ /**
203
+ * Get file reference of the Blob object.
204
+ * @return Blob file reference which can be consumed by ReactNativeBlobUtil fs
205
+ */
206
+ getReactNativeBlobUtilRef(): string;
207
+
208
+ /**
209
+ * Create a Blob object which is sliced from current object
210
+ * @param start Start byte number
211
+ * @param end End byte number
212
+ * @param contentType Optional, content type of new Blob object
213
+ */
214
+ slice(start?: number, end?: number, contentType?: string): PolyfillBlob;
215
+
216
+ /**
217
+ * Read data of the Blob object, this is not standard method.
218
+ * @param encoding Read data with encoding
219
+ */
220
+ readBlob(encoding: string): Promise<any>;
221
+
222
+ /**
223
+ * Release the resource of the Blob object.
224
+ * @nonstandard
225
+ */
226
+ close(): Promise<void>;
220
227
  }
221
228
 
222
229
  export declare namespace PolyfillBlob {
223
- function clearCache(): void;
230
+ function clearCache(): void;
224
231
 
225
- function build(data: any, cType: any): Promise<PolyfillBlob>;
232
+ function build(data: any, cType: any): Promise<PolyfillBlob>;
226
233
 
227
- function setLog(level: number): void;
234
+ function setLog(level: number): void;
228
235
  }
229
236
 
230
237
  export declare class PolyfillFile extends PolyfillBlob {}
231
238
 
232
- export interface PolyfillXMLHttpRequest extends PolyfillXMLHttpRequestEventTarget {
233
- upload: PolyfillXMLHttpRequestEventTarget;
234
- readonly UNSENT: number;
235
- readonly OPENED: number;
236
- readonly HEADERS_RECEIVED: number;
237
- readonly LOADING: number;
238
- readonly DONE: number;
239
-
240
- /**
241
- * XMLHttpRequest.open, always async, user and password not supported. When
242
- * this method invoked, headers should becomes empty again.
243
- * @param method Request method
244
- * @param url Request URL
245
- * @param async Always async
246
- * @param user NOT SUPPORTED
247
- * @param password NOT SUPPORTED
248
- */
249
- open(method: string, url: string, async: true, user: any, password: any): void;
250
-
251
- /**
252
- * Invoke this function to send HTTP request, and set body.
253
- * @param body Body in ReactNativeBlobUtil flavor
254
- */
255
- send(body: any): void;
256
-
257
- overrideMimeType(mime: string): void;
258
-
259
- setRequestHeader(name: string, value: string): void;
260
-
261
- abort(): void;
262
-
263
- getResponseHeader(field: string): string | null;
264
-
265
- getAllResponseHeaders(): string | null;
266
-
267
- onreadystatechange(e: Event): void;
268
-
269
- readyState: number;
270
- status: number;
271
- statusText: string;
272
- response: any;
273
- responseText: any;
274
- responseURL: string;
275
- responseHeaders: any;
276
- timeout: number;
277
- responseType: string;
239
+ export interface PolyfillXMLHttpRequest
240
+ extends PolyfillXMLHttpRequestEventTarget {
241
+ upload: PolyfillXMLHttpRequestEventTarget;
242
+ readonly UNSENT: number;
243
+ readonly OPENED: number;
244
+ readonly HEADERS_RECEIVED: number;
245
+ readonly LOADING: number;
246
+ readonly DONE: number;
247
+
248
+ /**
249
+ * XMLHttpRequest.open, always async, user and password not supported. When
250
+ * this method invoked, headers should becomes empty again.
251
+ * @param method Request method
252
+ * @param url Request URL
253
+ * @param async Always async
254
+ * @param user NOT SUPPORTED
255
+ * @param password NOT SUPPORTED
256
+ */
257
+ open(
258
+ method: string,
259
+ url: string,
260
+ async: true,
261
+ user: any,
262
+ password: any
263
+ ): void;
264
+
265
+ /**
266
+ * Invoke this function to send HTTP request, and set body.
267
+ * @param body Body in ReactNativeBlobUtil flavor
268
+ */
269
+ send(body: any): void;
270
+
271
+ overrideMimeType(mime: string): void;
272
+
273
+ setRequestHeader(name: string, value: string): void;
274
+
275
+ abort(): void;
276
+
277
+ getResponseHeader(field: string): string | null;
278
+
279
+ getAllResponseHeaders(): string | null;
280
+
281
+ onreadystatechange(e: Event): void;
282
+
283
+ readyState: number;
284
+ status: number;
285
+ statusText: string;
286
+ response: any;
287
+ responseText: any;
288
+ responseURL: string;
289
+ responseHeaders: any;
290
+ timeout: number;
291
+ responseType: string;
278
292
  }
279
293
 
280
294
  export declare namespace PolyfillXMLHttpRequest {
281
- const binaryContentTypes: string[];
282
- const UNSENT: number;
283
- const OPENED: number;
284
- const HEADERS_RECEIVED: number;
285
- const LOADING: number;
286
- const DONE: number;
295
+ const binaryContentTypes: string[];
296
+ const UNSENT: number;
297
+ const OPENED: number;
298
+ const HEADERS_RECEIVED: number;
299
+ const LOADING: number;
300
+ const DONE: number;
287
301
 
288
- function setLog(level: number): void;
302
+ function setLog(level: number): void;
289
303
 
290
- function addBinaryContentType(substr: string): void;
304
+ function addBinaryContentType(substr: string): void;
291
305
 
292
- function removeBinaryContentType(): void;
306
+ function removeBinaryContentType(): void;
293
307
  }
294
308
 
295
309
  export interface PolyfillXMLHttpRequestEventTarget extends EventTarget {
296
- onabort(e: Event): void;
310
+ onabort(e: Event): void;
297
311
 
298
- onerror(e: Event): void;
312
+ onerror(e: Event): void;
299
313
 
300
- onload(e: Event): void;
314
+ onload(e: Event): void;
301
315
 
302
- onloadstart(e: Event): void;
316
+ onloadstart(e: Event): void;
303
317
 
304
- onprogress(e: Event): void;
318
+ onprogress(e: Event): void;
305
319
 
306
- ontimeout(e: Event): void;
320
+ ontimeout(e: Event): void;
307
321
 
308
- onloadend(e: Event): void;
322
+ onloadend(e: Event): void;
309
323
  }
310
324
 
311
325
  export interface Net {
312
- /**
313
- * Get cookie according to the given url.
314
- * @param domain Domain of the cookies to be removed, remove all
315
- * @return Cookies of a specific domain.
316
- */
317
- getCookies(domain: string): Promise<string[]>;
326
+ /**
327
+ * Get cookie according to the given url.
328
+ * @param domain Domain of the cookies to be removed, remove all
329
+ * @return Cookies of a specific domain.
330
+ */
331
+ getCookies(domain: string): Promise<string[]>;
318
332
 
319
- /**
320
- * Remove cookies for a specific domain
321
- * @param domain Domain of the cookies to be removed, remove all
322
- * cookies when this is null.
323
- */
324
- removeCookies(domain?: string): Promise<null>;
333
+ /**
334
+ * Remove cookies for a specific domain
335
+ * @param domain Domain of the cookies to be removed, remove all
336
+ * cookies when this is null.
337
+ */
338
+ removeCookies(domain?: string): Promise<null>;
325
339
  }
326
340
 
327
- type HashAlgorithm = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
341
+ type HashAlgorithm = 'md5' | 'sha1' | 'sha224' | 'sha256' | 'sha384' | 'sha512';
328
342
 
329
343
  export interface FS {
330
- ReactNativeBlobUtilSession: ReactNativeBlobUtilSession;
331
-
332
- /**
333
- * Remove file at path.
334
- * @param path:string Path of target file.
335
- */
336
- unlink(path: string): Promise<void>;
337
-
338
- /**
339
- * Create a directory.
340
- * @param path Path of directory to be created
341
- */
342
- mkdir(path: string): Promise<void>;
343
-
344
- /**
345
- * Get a file cache session
346
- * @param name Stream ID
347
- */
348
- session(name: string): ReactNativeBlobUtilSession;
349
-
350
- ls(path: string): Promise<string[]>;
351
-
352
- /**
353
- * Read the file from the given path and calculate a cryptographic hash sum over its contents.
354
- *
355
- * @param path Path to the file
356
- * @param algorithm The hash algorithm to use
357
- */
358
- hash(path: string, algorithm: HashAlgorithm): Promise<string>;
359
-
360
- /**
361
- * Create file stream from file at `path`.
362
- * @param path The file path.
363
- * @param encoding Data encoding, should be one of `base64`, `utf8`, `ascii`
364
- * @param bufferSize Size of stream buffer.
365
- * @return ReactNativeBlobUtilStream stream instance.
366
- */
367
- readStream(path: string, encoding: Encoding, bufferSize?: number, tick?: number): Promise<ReactNativeBlobUtilReadStream>;
368
-
369
- mv(path: string, dest: string): Promise<boolean>;
370
-
371
- cp(path: string, dest: string): Promise<boolean>;
372
-
373
- /**
374
- * Create write stream to a file.
375
- * @param path Target path of file stream.
376
- * @param encoding Encoding of input data.
377
- * @param append A flag represent if data append to existing ones.
378
- * @return A promise resolves a `WriteStream` object.
379
- */
380
- writeStream(path: string, encoding: Encoding, append?: boolean): Promise<ReactNativeBlobUtilWriteStream>;
381
-
382
- /**
383
- * Write data to file.
384
- * @param path Path of the file.
385
- * @param data Data to write to the file.
386
- * @param encoding Encoding of data (Optional).
387
- */
388
- writeFile(path: string, data: string | number[], encoding?: Encoding): Promise<void>;
389
-
390
- /**
391
- * Processes the data and then writes to the file.
392
- * @param path Path of the file.
393
- * @param data Data to write to the file.
394
- * @param encoding Encoding of data (Optional).
395
- */
396
- writeFileWithTransform(path: string, data: string | number[], encoding?: Encoding): Promise<void>;
397
-
398
- appendFile(path: string, data: string | number[], encoding?: Encoding | "uri"): Promise<number>;
399
-
400
- /**
401
- * Wrapper method of readStream.
402
- * @param path Path of the file.
403
- * @param encoding Encoding of read stream.
404
- */
405
- readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
406
-
407
- /**
408
- * Reads from a file and then processes the data before returning
409
- * @param path Path of the file.
410
- * @param encoding Encoding of read stream.
411
- */
412
- readFileWithTransform(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
413
-
414
- /**
415
- * Check if file exists and if it is a folder.
416
- * @param path Path to check
417
- */
418
- exists(path: string): Promise<boolean>;
419
-
420
- createFile(path: string, data: string, encoding: Encoding): Promise<void>;
421
-
422
- isDir(path: string): Promise<boolean>;
423
-
424
- /**
425
- * Show statistic data of a path.
426
- * @param path Target path
427
- */
428
- stat(path: string): Promise<ReactNativeBlobUtilStat>;
429
-
430
- lstat(path: string): Promise<ReactNativeBlobUtilStat[]>;
431
-
432
- /**
433
- * Android only method, request media scanner to scan the file.
434
- * @param pairs Array contains Key value pairs with key `path` and `mime`.
435
- */
436
- scanFile(pairs: Array<{ [key: string]: string }>): Promise<void>;
437
-
438
- dirs: Dirs;
439
-
440
- slice(src: string, dest: string, start: number, end: number): Promise<void>;
441
-
442
- asset(path: string): string;
443
-
444
- df(): Promise<RNFetchBlobDf>;
445
-
446
- /**
447
- * Returns the path for the app group.
448
- * @param {string} groupName Name of app group
449
- */
450
- pathForAppGroup(groupName: string): Promise<string>;
344
+ ReactNativeBlobUtilSession: ReactNativeBlobUtilSession;
345
+
346
+ /**
347
+ * Remove file at path.
348
+ * @param path:string Path of target file.
349
+ */
350
+ unlink(path: string): Promise<void>;
351
+
352
+ /**
353
+ * Create a directory.
354
+ * @param path Path of directory to be created
355
+ */
356
+ mkdir(path: string): Promise<void>;
357
+
358
+ /**
359
+ * Get a file cache session
360
+ * @param name Stream ID
361
+ */
362
+ session(name: string): ReactNativeBlobUtilSession;
363
+
364
+ ls(path: string): Promise<string[]>;
365
+
366
+ /**
367
+ * Read the file from the given path and calculate a cryptographic hash sum over its contents.
368
+ *
369
+ * @param path Path to the file
370
+ * @param algorithm The hash algorithm to use
371
+ */
372
+ hash(path: string, algorithm: HashAlgorithm): Promise<string>;
373
+
374
+ /**
375
+ * Create file stream from file at `path`.
376
+ * @param path The file path.
377
+ * @param encoding Data encoding, should be one of `base64`, `utf8`, `ascii`
378
+ * @param bufferSize Size of stream buffer.
379
+ * @return ReactNativeBlobUtilStream stream instance.
380
+ */
381
+ readStream(
382
+ path: string,
383
+ encoding: Encoding,
384
+ bufferSize?: number,
385
+ tick?: number
386
+ ): Promise<ReactNativeBlobUtilReadStream>;
387
+
388
+ mv(path: string, dest: string): Promise<boolean>;
389
+
390
+ cp(path: string, dest: string): Promise<boolean>;
391
+
392
+ /**
393
+ * Create write stream to a file.
394
+ * @param path Target path of file stream.
395
+ * @param encoding Encoding of input data.
396
+ * @param append A flag represent if data append to existing ones.
397
+ * @return A promise resolves a `WriteStream` object.
398
+ */
399
+ writeStream(
400
+ path: string,
401
+ encoding: Encoding,
402
+ append?: boolean
403
+ ): Promise<ReactNativeBlobUtilWriteStream>;
404
+
405
+ /**
406
+ * Write data to file.
407
+ * @param path Path of the file.
408
+ * @param data Data to write to the file.
409
+ * @param encoding Encoding of data (Optional).
410
+ */
411
+ writeFile(
412
+ path: string,
413
+ data: string | number[],
414
+ encoding?: Encoding
415
+ ): Promise<void>;
416
+
417
+ /**
418
+ * Processes the data and then writes to the file.
419
+ * @param path Path of the file.
420
+ * @param data Data to write to the file.
421
+ * @param encoding Encoding of data (Optional).
422
+ */
423
+ writeFileWithTransform(
424
+ path: string,
425
+ data: string | number[],
426
+ encoding?: Encoding
427
+ ): Promise<void>;
428
+
429
+ appendFile(
430
+ path: string,
431
+ data: string | number[],
432
+ encoding?: Encoding | 'uri'
433
+ ): Promise<number>;
434
+
435
+ /**
436
+ * Wrapper method of readStream.
437
+ * @param path Path of the file.
438
+ * @param encoding Encoding of read stream.
439
+ */
440
+ readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
441
+
442
+ /**
443
+ * Reads from a file and then processes the data before returning
444
+ * @param path Path of the file.
445
+ * @param encoding Encoding of read stream.
446
+ */
447
+ readFileWithTransform(
448
+ path: string,
449
+ encoding: Encoding,
450
+ bufferSize?: number
451
+ ): Promise<any>;
452
+
453
+ /**
454
+ * Check if file exists and if it is a folder.
455
+ * @param path Path to check
456
+ */
457
+ exists(path: string): Promise<boolean>;
458
+
459
+ createFile(path: string, data: string, encoding: Encoding): Promise<void>;
460
+
461
+ isDir(path: string): Promise<boolean>;
462
+
463
+ /**
464
+ * Show statistic data of a path.
465
+ * @param path Target path
466
+ */
467
+ stat(path: string): Promise<ReactNativeBlobUtilStat>;
468
+
469
+ lstat(path: string): Promise<ReactNativeBlobUtilStat[]>;
470
+
471
+ /**
472
+ * Android only method, request media scanner to scan the file.
473
+ * @param pairs Array contains Key value pairs with key `path` and `mime`.
474
+ */
475
+ scanFile(pairs: Array<{ [key: string]: string }>): Promise<void>;
476
+
477
+ dirs: Dirs;
478
+
479
+ slice(src: string, dest: string, start: number, end: number): Promise<void>;
480
+
481
+ asset(path: string): string;
482
+
483
+ df(): Promise<RNFetchBlobDf>;
484
+
485
+ /**
486
+ * Returns the path for the app group.
487
+ * @param {string} groupName Name of app group
488
+ */
489
+ pathForAppGroup(groupName: string): Promise<string>;
451
490
  }
452
491
 
453
492
  export interface RNFetchBlobDfIOS {
454
- free?: number;
455
- total?: number;
493
+ free?: number;
494
+ total?: number;
456
495
  }
457
496
 
458
497
  export interface RNFetchBlobDfAndroid {
459
- external_free?: string;
460
- external_total?: string;
461
- internal_free?: string;
462
- internal_total?: string;
498
+ external_free?: string;
499
+ external_total?: string;
500
+ internal_free?: string;
501
+ internal_total?: string;
463
502
  }
464
503
 
465
504
  export type RNFetchBlobDf = RNFetchBlobDfIOS & RNFetchBlobDfAndroid;
466
505
 
467
506
  export interface Dirs {
468
- DocumentDir: string;
469
- CacheDir: string;
470
- PictureDir: string;
471
- LibraryDir: string;
472
- MusicDir: string;
473
- MovieDir: string;
474
- DownloadDir: string;
475
- DCIMDir: string;
476
- SDCardDir: string;
477
- MainBundleDir: string;
478
-
479
- LegacyPictureDir: string;
480
- LegacyMusicDir: string;
481
- LegacyMovieDir: string;
482
- LegacyDownloadDir: string;
483
- LegacyDCIMDir: string;
484
- LegacySDCardDir: string; // Depracated
507
+ DocumentDir: string;
508
+ CacheDir: string;
509
+ PictureDir: string;
510
+ LibraryDir: string;
511
+ MusicDir: string;
512
+ MovieDir: string;
513
+ DownloadDir: string;
514
+ DCIMDir: string;
515
+ SDCardDir: string;
516
+ MainBundleDir: string;
517
+
518
+ LegacyPictureDir: string;
519
+ LegacyMusicDir: string;
520
+ LegacyMovieDir: string;
521
+ LegacyDownloadDir: string;
522
+ LegacyDCIMDir: string;
523
+ LegacySDCardDir: string; // Depracated
485
524
  }
486
525
 
487
526
  export interface ReactNativeBlobUtilWriteStream {
488
- id: string;
489
- encoding: string;
490
- append: boolean;
527
+ id: string;
528
+ encoding: string;
529
+ append: boolean;
491
530
 
492
- write(data: string): Promise<void>;
531
+ write(data: string): Promise<void>;
493
532
 
494
- close(): Promise<void>;
533
+ close(): Promise<void>;
495
534
  }
496
535
 
497
536
  export interface ReactNativeBlobUtilReadStream {
498
- path: string;
499
- encoding: Encoding;
500
- bufferSize?: number;
501
- closed: boolean;
502
- tick: number;
537
+ path: string;
538
+ encoding: Encoding;
539
+ bufferSize?: number;
540
+ closed: boolean;
541
+ tick: number;
503
542
 
504
- open(): void;
543
+ open(): void;
505
544
 
506
- onData(fn: (chunk: string | number[]) => void): void;
545
+ onData(fn: (chunk: string | number[]) => void): void;
507
546
 
508
- onError(fn: (err: any) => void): void;
547
+ onError(fn: (err: any) => void): void;
509
548
 
510
- onEnd(fn: () => void): void;
549
+ onEnd(fn: () => void): void;
511
550
  }
512
551
 
513
- export type Encoding = "utf8" | "ascii" | "base64";
552
+ export type Encoding = 'utf8' | 'ascii' | 'base64';
514
553
 
515
554
  /* tslint:disable-next-line interface-name*/
516
555
  export interface IOSApi {
517
- /**
518
- * Open a file in {@link https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller UIDocumentInteractionController},
519
- * this is the default document viewer of iOS, supports several kinds of files. On Android, there's an similar method {@link android.actionViewIntent}.
520
- * @param path This is a required field, the path to the document. The path should NOT contain any scheme prefix.
521
- * @param {string} scheme URI scheme that needs to support, optional
522
- */
523
- previewDocument(path: string, scheme?: string): void;
524
-
525
- /**
526
- * Show options menu for interact with the file.
527
- * @param path This is a required field, the path to the document. The path should NOT contain any scheme prefix.
528
- * @param {string} scheme URI scheme that needs to support, optional
529
- */
530
- openDocument(path: string, scheme?: string): Promise<void>;
531
-
532
- /**
533
- * Displays an options menu using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentOptionsMenu](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616814-presentoptionsmenu)
534
- * @param {string} path Path of the file to be open.
535
- * @param {string} scheme URI scheme that needs to support, optional
536
- */
537
- presentOptionsMenu(path: string, scheme?: string): void;
538
-
539
- /**
540
- * Displays a menu for opening the document using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentOpenInMenu](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616807-presentopeninmenu)
541
- * @param {string} path Path of the file to be open.
542
- * @param {string} scheme URI scheme that needs to support, optional
543
- */
544
- presentOpenInMenu(path: string, scheme?: string): void;
545
-
546
- /**
547
- * Displays a full-screen preview of the target document using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentPreview](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616828-presentpreview)
548
- * @param {string} path Path of the file to be open.
549
- * @param {string} scheme URI scheme that needs to support, optional
550
- */
551
- presentPreview(path: string, scheme?: string): void;
552
-
553
- /**
554
- * Marks the file to be excluded from icloud/itunes backup. Works recursively if path is to a directory
555
- * @param {string} path Path to a file or directory to mark to be excluded.
556
- */
557
- excludeFromBackupKey(path: string): Promise<void>;
556
+ /**
557
+ * Open a file in {@link https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller UIDocumentInteractionController},
558
+ * this is the default document viewer of iOS, supports several kinds of files. On Android, there's an similar method {@link android.actionViewIntent}.
559
+ * @param path This is a required field, the path to the document. The path should NOT contain any scheme prefix.
560
+ * @param {string} scheme URI scheme that needs to support, optional
561
+ */
562
+ previewDocument(path: string, scheme?: string): void;
563
+
564
+ /**
565
+ * Show options menu for interact with the file.
566
+ * @param path This is a required field, the path to the document. The path should NOT contain any scheme prefix.
567
+ * @param {string} scheme URI scheme that needs to support, optional
568
+ */
569
+ openDocument(path: string, scheme?: string): Promise<void>;
570
+
571
+ /**
572
+ * Displays an options menu using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentOptionsMenu](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616814-presentoptionsmenu)
573
+ * @param {string} path Path of the file to be open.
574
+ * @param {string} scheme URI scheme that needs to support, optional
575
+ */
576
+ presentOptionsMenu(path: string, scheme?: string): void;
577
+
578
+ /**
579
+ * Displays a menu for opening the document using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentOpenInMenu](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616807-presentopeninmenu)
580
+ * @param {string} path Path of the file to be open.
581
+ * @param {string} scheme URI scheme that needs to support, optional
582
+ */
583
+ presentOpenInMenu(path: string, scheme?: string): void;
584
+
585
+ /**
586
+ * Displays a full-screen preview of the target document using [UIDocumentInteractionController](https://developer.apple.com/reference/uikit/uidocumentinteractioncontroller).[presentPreview](https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller/1616828-presentpreview)
587
+ * @param {string} path Path of the file to be open.
588
+ * @param {string} scheme URI scheme that needs to support, optional
589
+ */
590
+ presentPreview(path: string, scheme?: string): void;
591
+
592
+ /**
593
+ * Marks the file to be excluded from icloud/itunes backup. Works recursively if path is to a directory
594
+ * @param {string} path Path to a file or directory to mark to be excluded.
595
+ */
596
+ excludeFromBackupKey(path: string): Promise<void>;
558
597
  }
559
598
 
560
599
  export interface AndroidDownloadOption {
561
- /**
562
- * Title string to be displayed when the file added to Downloads app.
563
- */
564
- title: string;
600
+ /**
601
+ * Title string to be displayed when the file added to Downloads app.
602
+ */
603
+ title: string;
565
604
 
566
- /**
567
- * File description to be displayed when the file added to Downloads app.
568
- */
569
- description: string;
605
+ /**
606
+ * File description to be displayed when the file added to Downloads app.
607
+ */
608
+ description: string;
570
609
 
571
- /**
572
- * MIME string of the file.
573
- */
574
- mime: string;
610
+ /**
611
+ * MIME string of the file.
612
+ */
613
+ mime: string;
575
614
 
576
- /**
577
- * URI string of the file.
578
- */
579
- path: string;
615
+ /**
616
+ * URI string of the file.
617
+ */
618
+ path: string;
580
619
 
581
- /**
582
- * Boolean value that determines if notification will be displayed.
583
- */
584
- showNotification: boolean;
620
+ /**
621
+ * Boolean value that determines if notification will be displayed.
622
+ */
623
+ showNotification: boolean;
585
624
  }
586
625
 
587
626
  export interface AndroidApi {
588
- /**
589
- * When sending an ACTION_VIEW intent with given file path and MIME type, system will try to open an
590
- * App to handle the file. For example, open Gallery app to view an image, or install APK.
591
- * @param path Path of the file to be opened.
592
- * @param mime Basically system will open an app according to this MIME type.
593
- * @param chooserTitle title for chooser, if not set the chooser won't be displayed (see [Android docs](https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)))
594
- */
595
- actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<boolean | null>;
596
-
597
- /**
598
- *
599
- * This method brings up OS default file picker and resolves a file URI when the user selected a file.
600
- * However, it does not resolve or reject when user dismiss the file picker via pressing hardware back button,
601
- * but you can still handle this behavior via AppState.
602
- * @param mime MIME type filter, only the files matches the MIME will be shown.
603
- */
604
- getContentIntent(mime: string): Promise<any>;
605
-
606
- /**
607
- * Using this function to add an existing file to Downloads app.
608
- * @param options An object that for setting the title, description, mime, and notification of the item.
609
- */
610
- addCompleteDownload(options: AndroidDownloadOption): Promise<void>;
611
-
612
- getSDCardDir(): Promise<string>;
613
-
614
- getSDCardApplicationDir(): Promise<string>;
615
- }
616
-
617
- type Methods = "POST" | "GET" | "DELETE" | "PUT" | "PATCH" | "post" | "get" | "delete" | "put" | "patch";
627
+ /**
628
+ * When sending an ACTION_VIEW intent with given file path and MIME type, system will try to open an
629
+ * App to handle the file. For example, open Gallery app to view an image, or install APK.
630
+ * @param path Path of the file to be opened.
631
+ * @param mime Basically system will open an app according to this MIME type.
632
+ * @param chooserTitle title for chooser, if not set the chooser won't be displayed (see [Android docs](https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence)))
633
+ */
634
+ actionViewIntent(
635
+ path: string,
636
+ mime: string,
637
+ chooserTitle?: string
638
+ ): Promise<boolean | null>;
639
+
640
+ /**
641
+ *
642
+ * This method brings up OS default file picker and resolves a file URI when the user selected a file.
643
+ * However, it does not resolve or reject when user dismiss the file picker via pressing hardware back button,
644
+ * but you can still handle this behavior via AppState.
645
+ * @param mime MIME type filter, only the files matches the MIME will be shown.
646
+ */
647
+ getContentIntent(mime: string): Promise<any>;
648
+
649
+ /**
650
+ * Using this function to add an existing file to Downloads app.
651
+ * @param options An object that for setting the title, description, mime, and notification of the item.
652
+ */
653
+ addCompleteDownload(options: AndroidDownloadOption): Promise<void>;
654
+
655
+ getSDCardDir(): Promise<string>;
656
+
657
+ getSDCardApplicationDir(): Promise<string>;
658
+ }
659
+
660
+ type Methods =
661
+ | 'POST'
662
+ | 'GET'
663
+ | 'DELETE'
664
+ | 'PUT'
665
+ | 'PATCH'
666
+ | 'post'
667
+ | 'get'
668
+ | 'delete'
669
+ | 'put'
670
+ | 'patch';
618
671
 
619
672
  /**
620
673
  * A declare class inherits Promise, it has extra method like progress, uploadProgress,
621
674
  * and cancel which can help managing an asynchronous task's state.
622
675
  */
623
676
  export interface StatefulPromise<T> extends Promise<T> {
624
- /**
625
- * Cancel the request when invoke this method.
626
- */
627
- cancel(cb?: (reason: any) => void): StatefulPromise<FetchBlobResponse>;
628
-
629
- /**
630
- * Add an event listener which triggers when data receiving from server.
631
- */
632
- progress(callback: (received: string, total: string) => void): StatefulPromise<FetchBlobResponse>;
633
-
634
- /**
635
- * Add an event listener with custom configuration
636
- */
637
- progress(config: { count?: number; interval?: number }, callback: (received: number, total: number) => void): StatefulPromise<FetchBlobResponse>;
638
-
639
- /**
640
- * Add an event listener with custom configuration.
641
- */
642
- uploadProgress(callback: (sent: number, total: number) => void): StatefulPromise<FetchBlobResponse>;
643
-
644
- /**
645
- * Add an event listener with custom configuration
646
- */
647
- uploadProgress(config: { count?: number; interval?: number }, callback: (sent: number, total: number) => void): StatefulPromise<FetchBlobResponse>;
648
-
649
- /**
650
- * An IOS only API, when IOS app turns into background network tasks will be terminated after ~180 seconds,
651
- * in order to handle these expired tasks, you can register an event handler, which will be called after the
652
- * app become active.
653
- */
654
- expire(callback: () => void): StatefulPromise<void>;
677
+ /**
678
+ * Cancel the request when invoke this method.
679
+ */
680
+ cancel(cb?: (reason: any) => void): StatefulPromise<FetchBlobResponse>;
681
+
682
+ /**
683
+ * Add an event listener which triggers when data receiving from server.
684
+ */
685
+ progress(
686
+ callback: (received: string, total: string) => void
687
+ ): StatefulPromise<FetchBlobResponse>;
688
+
689
+ /**
690
+ * Add an event listener with custom configuration
691
+ */
692
+ progress(
693
+ config: { count?: number; interval?: number },
694
+ callback: (received: number, total: number) => void
695
+ ): StatefulPromise<FetchBlobResponse>;
696
+
697
+ /**
698
+ * Add an event listener with custom configuration.
699
+ */
700
+ uploadProgress(
701
+ callback: (sent: number, total: number) => void
702
+ ): StatefulPromise<FetchBlobResponse>;
703
+
704
+ /**
705
+ * Add an event listener with custom configuration
706
+ */
707
+ uploadProgress(
708
+ config: { count?: number; interval?: number },
709
+ callback: (sent: number, total: number) => void
710
+ ): StatefulPromise<FetchBlobResponse>;
711
+
712
+ /**
713
+ * An IOS only API, when IOS app turns into background network tasks will be terminated after ~180 seconds,
714
+ * in order to handle these expired tasks, you can register an event handler, which will be called after the
715
+ * app become active.
716
+ */
717
+ expire(callback: () => void): StatefulPromise<void>;
655
718
  }
656
719
 
657
720
  export declare class ReactNativeBlobUtilSession {
658
- constructor(name: string, list: string[]);
721
+ constructor(name: string, list: string[]);
659
722
 
660
- add(path: string): ReactNativeBlobUtilSession;
723
+ add(path: string): ReactNativeBlobUtilSession;
661
724
 
662
- remove(path: string): ReactNativeBlobUtilSession;
725
+ remove(path: string): ReactNativeBlobUtilSession;
663
726
 
664
- dispose(): Promise<void>;
727
+ dispose(): Promise<void>;
665
728
 
666
- list(): string[];
729
+ list(): string[];
667
730
 
668
- name: string;
731
+ name: string;
669
732
 
670
- static getSession(name: string): any;
733
+ static getSession(name: string): any;
671
734
 
672
- static setSession(name: string): void;
735
+ static setSession(name: string): void;
673
736
 
674
- static removeSession(name: string): void;
737
+ static removeSession(name: string): void;
675
738
  }
676
739
 
677
740
  /**
678
741
  * A set of configurations that will be injected into a fetch method, with the following properties.
679
742
  */
680
743
  export interface ReactNativeBlobUtilConfig {
681
- Progress?: { count?: number; interval?: number };
682
- UploadProgress?: { count?: number; interval?: number };
683
-
684
- /**
685
- * When this property is true, the downloaded data will overwrite the existing file. (true by default)
686
- */
687
- overwrite?: boolean;
688
-
689
- /**
690
- * Set timeout of the request (in milliseconds).
691
- */
692
- timeout?: number;
693
-
694
- /**
695
- * Set this property to true to display a network indicator on status bar, this feature is only supported on IOS.
696
- */
697
- indicator?: boolean;
698
-
699
- /**
700
- * Set this property to true will allow the request create connection with server have self-signed SSL
701
- * certification. This is not recommended to use in production.
702
- */
703
- trusty?: boolean;
704
-
705
- /**
706
- * Set this property to true will only do requests through the WiFi interface, and fail otherwise.
707
- */
708
- wifiOnly?: boolean;
709
-
710
- /**
711
- * Set this property so redirects are not automatically followed.
712
- */
713
- followRedirect?: boolean;
714
-
715
- /**
716
- * Set this property to true will makes response data of the fetch stored in a temp file, by default the temp
717
- * file will stored in App's own root folder with file name template ReactNativeBlobUtil_tmp${timestamp}.
718
- */
719
- fileCache?: boolean;
720
-
721
- /**
722
- * Set this property to true if you want the data to be processed before it gets written onto disk.
723
- * This only has effect if the FileTransformer has been registered and the library is configured to write
724
- * response onto disk.
725
- */
726
- transformFile?: boolean;
727
-
728
- /**
729
- * Set this property to change temp file extension that created by fetch response data.
730
- */
731
- appendExt?: string;
732
-
733
- /**
734
- * When this property has value, fetch API will try to store response data in the path ignoring fileCache and
735
- * appendExt property.
736
- */
737
- path?: string;
738
-
739
- session?: string;
740
-
741
- addAndroidDownloads?: AddAndroidDownloads;
742
-
743
- /**
744
- * Fix IOS request timeout issue #368 by change default request setting to defaultSessionConfiguration, and make backgroundSessionConfigurationWithIdentifier optional
745
- */
746
- IOSBackgroundTask?: boolean;
744
+ Progress?: { count?: number; interval?: number };
745
+ UploadProgress?: { count?: number; interval?: number };
746
+
747
+ /**
748
+ * When this property is true, the downloaded data will overwrite the existing file. (true by default)
749
+ */
750
+ overwrite?: boolean;
751
+
752
+ /**
753
+ * Set timeout of the request (in milliseconds).
754
+ */
755
+ timeout?: number;
756
+
757
+ /**
758
+ * Set this property to true to display a network indicator on status bar, this feature is only supported on IOS.
759
+ */
760
+ indicator?: boolean;
761
+
762
+ /**
763
+ * Set this property to true will allow the request create connection with server have self-signed SSL
764
+ * certification. This is not recommended to use in production.
765
+ */
766
+ trusty?: boolean;
767
+
768
+ /**
769
+ * Set this property to true will only do requests through the WiFi interface, and fail otherwise.
770
+ */
771
+ wifiOnly?: boolean;
772
+
773
+ /**
774
+ * Set this property so redirects are not automatically followed.
775
+ */
776
+ followRedirect?: boolean;
777
+
778
+ /**
779
+ * Set this property to true will makes response data of the fetch stored in a temp file, by default the temp
780
+ * file will stored in App's own root folder with file name template ReactNativeBlobUtil_tmp${timestamp}.
781
+ */
782
+ fileCache?: boolean;
783
+
784
+ /**
785
+ * Set this property to true if you want the data to be processed before it gets written onto disk.
786
+ * This only has effect if the FileTransformer has been registered and the library is configured to write
787
+ * response onto disk.
788
+ */
789
+ transformFile?: boolean;
790
+
791
+ /**
792
+ * Set this property to change temp file extension that created by fetch response data.
793
+ */
794
+ appendExt?: string;
795
+
796
+ /**
797
+ * When this property has value, fetch API will try to store response data in the path ignoring fileCache and
798
+ * appendExt property.
799
+ */
800
+ path?: string;
801
+
802
+ session?: string;
803
+
804
+ addAndroidDownloads?: AddAndroidDownloads;
805
+
806
+ /**
807
+ * Fix IOS request timeout issue #368 by change default request setting to defaultSessionConfiguration, and make backgroundSessionConfigurationWithIdentifier optional
808
+ */
809
+ IOSBackgroundTask?: boolean;
747
810
  }
748
811
 
749
812
  export interface AddAndroidDownloads {
750
- /**
751
- * download file using Android download manager or not.
752
- */
753
- useDownloadManager?: boolean;
754
- /**
755
- * title of the file
756
- */
757
- title?: string;
758
- /**
759
- * File description of the file.
760
- */
761
- description?: string;
762
- /**
763
- * The destination which the file will be downloaded, it SHOULD be a location on external storage (DCIMDir).
764
- */
765
- path?: string;
766
- /**
767
- * MIME type of the file. By default is text/plain
768
- */
769
- mime?: string;
770
- /**
771
- * A boolean value, see Officail Document
772
- * (https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean))
773
- */
774
- mediaScannable?: boolean;
775
- /**
776
- * Only for Android >= Q; Enforces the file being stored to the MediaCollection Downloads. This might overwrite any value given in "path"
777
- */
778
- storeInDownloads?: boolean;
779
- /**
780
- * A boolean value decide whether show a notification when download complete.
781
- */
782
- notification?: boolean;
813
+ /**
814
+ * download file using Android download manager or not.
815
+ */
816
+ useDownloadManager?: boolean;
817
+ /**
818
+ * title of the file
819
+ */
820
+ title?: string;
821
+ /**
822
+ * File description of the file.
823
+ */
824
+ description?: string;
825
+ /**
826
+ * The destination which the file will be downloaded, it SHOULD be a location on external storage (DCIMDir).
827
+ */
828
+ path?: string;
829
+ /**
830
+ * MIME type of the file. By default is text/plain
831
+ */
832
+ mime?: string;
833
+ /**
834
+ * A boolean value, see Officail Document
835
+ * (https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean))
836
+ */
837
+ mediaScannable?: boolean;
838
+ /**
839
+ * Only for Android >= Q; Enforces the file being stored to the MediaCollection Downloads. This might overwrite any value given in "path"
840
+ */
841
+ storeInDownloads?: boolean;
842
+ /**
843
+ * A boolean value decide whether show a notification when download complete.
844
+ */
845
+ notification?: boolean;
783
846
  }
784
847
 
785
848
  export interface ReactNativeBlobUtilResponseInfo {
786
- taskId: string;
787
- state: string;
788
- headers: any;
789
- redirects: string[];
790
- status: number;
791
- respType: "text" | "blob" | "" | "json";
792
- rnfbEncode: "path" | "base64" | "ascii" | "utf8";
793
- timeout: boolean;
849
+ taskId: string;
850
+ state: string;
851
+ headers: any;
852
+ redirects: string[];
853
+ status: number;
854
+ respType: 'text' | 'blob' | '' | 'json';
855
+ rnfbEncode: 'path' | 'base64' | 'ascii' | 'utf8';
856
+ timeout: boolean;
794
857
  }
795
858
 
796
859
  export interface ReactNativeBlobUtilStream {
797
- onData(): void;
860
+ onData(): void;
798
861
 
799
- onError(): void;
862
+ onError(): void;
800
863
 
801
- onEnd(): void;
864
+ onEnd(): void;
802
865
  }
803
866
 
804
867
  export declare class ReactNativeBlobUtilFile {}
805
868
 
806
869
  export declare class ReactNativeBlobUtilStat {
807
- lastModified: number;
808
- size: number;
809
- type: "directory" | "file";
810
- path: string;
811
- filename: string;
870
+ lastModified: number;
871
+ size: number;
872
+ type: 'directory' | 'file';
873
+ path: string;
874
+ filename: string;
812
875
  }
813
876
 
814
- export type Mediatype = "Audio" | "Image" | "Video" | "Download";
877
+ export type Mediatype = 'Audio' | 'Image' | 'Video' | 'Download';
815
878
 
816
879
  export interface MediaCollection {
817
- /**
818
- * Creates a new File in the collection.
819
- * Promise will resolve to content UIR or error message
820
- * @param filedata descriptor for the media store entry
821
- * @param mediatype
822
- * @param path path of the file being copied
823
- */
824
- copyToMediaStore(filedata: filedescriptor, mediatype: Mediatype, path: string): Promise<string>;
825
-
826
- /**
827
- * Creates a new File in the collection.
828
- * @param filedata
829
- * @param mediatype
830
- */
831
- createMediafile(filedata: filedescriptor, mediatype: Mediatype): Promise<string>;
832
-
833
- /**
834
- * Copies an existing file to a mediastore file
835
- * @param uri URI of the destination mediastore file
836
- * @param path Path to the existing file which should be copied
837
- */
838
- writeToMediafile(uri: string, path: string): Promise<string>;
839
-
840
- /**
841
- * Copies and transforms an existing file to a mediastore file. Make sure FileTransformer is set
842
- * @param uri URI of the destination mediastore file
843
- * @param path Path to the existing file which should be copied
844
- */
845
- writeToMediafileWithTransform(uri: string, path: string): Promise<string>;
846
-
847
- /**
848
- * Copies a file from the mediastore to the apps internal storage
849
- * @param contenturi URI of the mediastore file
850
- * @param destpath Path for the file in the internal storage
851
- */
852
- copyToInternal(contenturi: string, destpath: string): Promise<string>;
853
-
854
- /**
855
- * Gets the blob data for a given URI in the mediastore
856
- * @param contenturi
857
- * @param encoding
858
- */
859
- getBlob(contenturi: string, encoding: string): Promise<string>;
880
+ /**
881
+ * Creates a new File in the collection.
882
+ * Promise will resolve to content UIR or error message
883
+ * @param filedata descriptor for the media store entry
884
+ * @param mediatype
885
+ * @param path path of the file being copied
886
+ */
887
+ copyToMediaStore(
888
+ filedata: filedescriptor,
889
+ mediatype: Mediatype,
890
+ path: string
891
+ ): Promise<string>;
892
+
893
+ /**
894
+ * Creates a new File in the collection.
895
+ * @param filedata
896
+ * @param mediatype
897
+ */
898
+ createMediafile(
899
+ filedata: filedescriptor,
900
+ mediatype: Mediatype
901
+ ): Promise<string>;
902
+
903
+ /**
904
+ * Copies an existing file to a mediastore file
905
+ * @param uri URI of the destination mediastore file
906
+ * @param path Path to the existing file which should be copied
907
+ */
908
+ writeToMediafile(uri: string, path: string): Promise<string>;
909
+
910
+ /**
911
+ * Copies and transforms an existing file to a mediastore file. Make sure FileTransformer is set
912
+ * @param uri URI of the destination mediastore file
913
+ * @param path Path to the existing file which should be copied
914
+ */
915
+ writeToMediafileWithTransform(uri: string, path: string): Promise<string>;
916
+
917
+ /**
918
+ * Copies a file from the mediastore to the apps internal storage
919
+ * @param contenturi URI of the mediastore file
920
+ * @param destpath Path for the file in the internal storage
921
+ */
922
+ copyToInternal(contenturi: string, destpath: string): Promise<string>;
923
+
924
+ /**
925
+ * Gets the blob data for a given URI in the mediastore
926
+ * @param contenturi
927
+ * @param encoding
928
+ */
929
+ getBlob(contenturi: string, encoding: string): Promise<string>;
860
930
  }