react-native-blob-util 0.22.2 → 0.23.2

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