react-native-blob-util 0.13.18 → 0.14.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 (24) hide show
  1. package/README.md +471 -406
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +86 -21
  4. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilBody.java +14 -15
  5. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +8 -6
  6. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +21 -286
  7. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilMediaCollection.java +278 -0
  8. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilPackage.java +6 -2
  9. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +17 -21
  10. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java +287 -0
  11. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java +57 -2
  12. package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +5 -0
  13. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -0
  14. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -0
  15. package/fs.js +2 -1
  16. package/index.d.ts +92 -1
  17. package/index.js +2 -0
  18. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.m +2 -1
  19. package/ios/ReactNativeBlobUtilFS.h +1 -0
  20. package/ios/ReactNativeBlobUtilFS.m +4 -0
  21. package/mediacollection.js +33 -0
  22. package/package.json +1 -1
  23. package/scripts/prelink.js +1 -1
  24. package/types.js +3 -0
package/index.d.ts CHANGED
@@ -6,17 +6,25 @@
6
6
  export const ReactNativeBlobUtil: ReactNativeBlobUtilStatic;
7
7
  export type ReactNativeBlobUtil = ReactNativeBlobUtilStatic;
8
8
  export default ReactNativeBlobUtil;
9
+ import {filedescriptor} from './types';
9
10
 
10
11
  interface ReactNativeBlobUtilStatic {
11
12
  fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any
12
13
  | null): StatefulPromise<FetchBlobResponse>;
14
+
13
15
  base64: { encode(input: string): string; decode(input: string): string };
14
16
  android: AndroidApi;
15
17
  ios: IOSApi;
18
+
16
19
  config(options: ReactNativeBlobUtilConfig): ReactNativeBlobUtilStatic;
20
+
17
21
  session(name: string): ReactNativeBlobUtilSession;
22
+
18
23
  fs: FS;
24
+ MediaCollection: MediaCollection;
25
+
19
26
  wrap(path: string): string;
27
+
20
28
  net: Net;
21
29
  polyfill: Polyfill;
22
30
  // this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
@@ -45,10 +53,15 @@ export declare class ReactNativeBlobUtilFetchPolyfill {
45
53
 
46
54
  export interface ReactNativeBlobUtilFetchRepsonse {
47
55
  arrayBuffer(): Promise<any[]>;
56
+
48
57
  blob(): Promise<PolyfillBlob>;
58
+
49
59
  json(): Promise<any>;
60
+
50
61
  rawResp(): Promise<FetchBlobResponse>;
62
+
51
63
  text(): Promise<string>;
64
+
52
65
  bodyUsed: boolean;
53
66
  headers: any;
54
67
  ok: boolean;
@@ -64,46 +77,58 @@ export interface ReactNativeBlobUtilFetchRepsonse {
64
77
  */
65
78
  export interface FetchBlobResponse {
66
79
  taskId: string;
80
+
67
81
  /**
68
82
  * get path of response temp file
69
83
  * @return File path of temp file.
70
84
  */
71
85
  path(): string;
86
+
72
87
  type: "base64" | "path" | "utf8";
73
88
  data: any;
89
+
74
90
  /**
75
91
  * Convert result to javascript ReactNativeBlobUtil object.
76
92
  * @return Return a promise resolves Blob object.
77
93
  */
78
94
  blob(contentType: string, sliceSize: number): Promise<PolyfillBlob>;
95
+
79
96
  /**
80
97
  * Convert result to text.
81
98
  * @return Decoded base64 string.
82
99
  */
83
100
  text(): string | Promise<any>;
101
+
84
102
  /**
85
103
  * Convert result to JSON object.
86
104
  * @return Parsed javascript object.
87
105
  */
88
106
  json(): any;
107
+
89
108
  /**
90
109
  * Return BASE64 string directly.
91
110
  * @return BASE64 string of response body.
92
111
  */
93
112
  base64(): any;
113
+
94
114
  /**
95
115
  * Remove cahced file
96
116
  */
97
117
  flush(): void;
118
+
98
119
  respInfo: ReactNativeBlobUtilResponseInfo;
120
+
99
121
  info(): ReactNativeBlobUtilResponseInfo;
122
+
100
123
  session(name: string): ReactNativeBlobUtilSession | null;
124
+
101
125
  /**
102
126
  * Read file content with given encoding, if the response does not contains
103
127
  * a file path, show warning message
104
128
  * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
105
129
  */
106
130
  readFile(encode: Encoding): Promise<any> | null;
131
+
107
132
  /**
108
133
  * Start read stream from cached file
109
134
  * @param encode Encode type, should be one of `base64`, `ascrii`, `utf8`.
@@ -113,17 +138,27 @@ export interface FetchBlobResponse {
113
138
 
114
139
  export interface PolyfillFileReader extends EventTarget {
115
140
  isRNFBPolyFill: boolean;
141
+
116
142
  onloadstart(e: Event): void;
143
+
117
144
  onprogress(e: Event): void;
145
+
118
146
  onload(e: Event): void;
147
+
119
148
  onabort(e: Event): void;
149
+
120
150
  onerror(e: Event): void;
151
+
121
152
  onloadend(e: Event): void;
122
153
 
123
154
  abort(): void;
155
+
124
156
  readAsArrayBuffer(b: PolyfillBlob): void;
157
+
125
158
  readAsBinaryString(b: PolyfillBlob): void;
159
+
126
160
  readAsText(b: PolyfillBlob, label?: string): void;
161
+
127
162
  readAsDataURL(b: PolyfillBlob): void;
128
163
 
129
164
  readyState: number;
@@ -242,6 +277,7 @@ export interface PolyfillXMLHttpRequest extends PolyfillXMLHttpRequestEventTarge
242
277
  getAllResponseHeaders(): string | null;
243
278
 
244
279
  onreadystatechange(e: Event): void;
280
+
245
281
  readyState: number;
246
282
  status: number;
247
283
  statusText: string;
@@ -270,11 +306,17 @@ export declare namespace PolyfillXMLHttpRequest {
270
306
 
271
307
  export interface PolyfillXMLHttpRequestEventTarget extends EventTarget {
272
308
  onabort(e: Event): void;
309
+
273
310
  onerror(e: Event): void;
311
+
274
312
  onload(e: Event): void;
313
+
275
314
  onloadstart(e: Event): void;
315
+
276
316
  onprogress(e: Event): void;
317
+
277
318
  ontimeout(e: Event): void;
319
+
278
320
  onloadend(e: Event): void;
279
321
  }
280
322
 
@@ -295,6 +337,7 @@ export interface Net {
295
337
  }
296
338
 
297
339
  type HashAlgorithm = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
340
+
298
341
  export interface FS {
299
342
  ReactNativeBlobUtilSession: ReactNativeBlobUtilSession;
300
343
 
@@ -364,6 +407,7 @@ export interface FS {
364
407
  * @param encoding Encoding of read stream.
365
408
  */
366
409
  readFile(path: string, encoding: Encoding, bufferSize?: number): Promise<any>;
410
+
367
411
  /**
368
412
  * Check if file exists and if it is a folder.
369
413
  * @param path Path to check
@@ -391,7 +435,9 @@ export interface FS {
391
435
  dirs: Dirs;
392
436
 
393
437
  slice(src: string, dest: string, start: number, end: number): Promise<void>;
438
+
394
439
  asset(path: string): string;
440
+
395
441
  df(): Promise<RNFetchBlobDf>;
396
442
  }
397
443
 
@@ -428,6 +474,7 @@ export interface ReactNativeBlobUtilWriteStream {
428
474
  append: boolean;
429
475
 
430
476
  write(data: string): Promise<void>;
477
+
431
478
  close(): void;
432
479
  }
433
480
 
@@ -526,7 +573,7 @@ export interface AndroidApi {
526
573
  actionViewIntent(path: string, mime: string, chooserTitle?: string): Promise<boolean | null>;
527
574
 
528
575
  /**
529
- *
576
+ *
530
577
  * This method brings up OS default file picker and resolves a file URI when the user selected a file.
531
578
  * However, it does not resolve or reject when user dismiss the file picker via pressing hardware back button,
532
579
  * but you can still handle this behavior via AppState.
@@ -717,7 +764,9 @@ export interface ReactNativeBlobUtilResponseInfo {
717
764
 
718
765
  export interface ReactNativeBlobUtilStream {
719
766
  onData(): void;
767
+
720
768
  onError(): void;
769
+
721
770
  onEnd(): void;
722
771
  }
723
772
 
@@ -731,3 +780,45 @@ export declare class ReactNativeBlobUtilStat {
731
780
  path: string;
732
781
  filename: string;
733
782
  }
783
+
784
+ export type Mediatype = "Audio" | "Image" | "Video" | "Download";
785
+
786
+ export interface MediaCollection {
787
+ /**
788
+ * Creates a new File in the collection.
789
+ * Promise will resolve to content UIR or error message
790
+ * @param filedata descriptor for the media store entry
791
+ * @param mediatype
792
+ * @param path path of the file being copied
793
+ */
794
+ copyToMediaStore(filedata: filedescriptor, mediatype: Mediatype, path: string): Promise<string>;
795
+
796
+
797
+ /**
798
+ * Creates a new File in the collection.
799
+ * @param filedata
800
+ * @param mediatype
801
+ */
802
+ createMediafile(filedata: filedescriptor, mediatype: Mediatype): Promise<string>;
803
+
804
+ /**
805
+ * Copies an existing file to a mediastore file
806
+ * @param uri URI of the destination mediastore file
807
+ * @param path Path to the existing file which should be copied
808
+ */
809
+ writeToMediafile(uri: string, path: string): Promise<string>
810
+
811
+ /**
812
+ * Copies a file from the mediastore to the apps internal storage
813
+ * @param contenturi URI of the mediastore file
814
+ * @param destpath Path for the file in the internal storage
815
+ */
816
+ copyToInternal(contenturi: string, destpath: string): Promise<string>
817
+
818
+ /**
819
+ * Gets the blob data for a given URI in the mediastore
820
+ * @param contenturi
821
+ * @param encoding
822
+ */
823
+ getBlob(contenturi: string, encoding: string): Promise<string>
824
+ }
package/index.js CHANGED
@@ -6,6 +6,7 @@ import {AppState, DeviceEventEmitter, NativeModules, Platform,} from 'react-nati
6
6
 
7
7
  //import StatefulPromise from './class/StatefulPromise.js'
8
8
  import fs from './fs';
9
+ import MediaCollection from './mediacollection';
9
10
  import base64 from 'base-64';
10
11
  import polyfill from './polyfill';
11
12
  import android from './android';
@@ -69,4 +70,5 @@ export default {
69
70
  wrap,
70
71
  polyfill,
71
72
  JSONStream,
73
+ MediaCollection
72
74
  };
@@ -76,6 +76,7 @@ RCT_EXPORT_MODULE();
76
76
  @"MovieDir" : [ReactNativeBlobUtilFS getMovieDir],
77
77
  @"MusicDir" : [ReactNativeBlobUtilFS getMusicDir],
78
78
  @"PictureDir" : [ReactNativeBlobUtilFS getPictureDir],
79
+ @"ApplicationSupportDir" : [ReactNativeBlobUtilFS getApplicationSupportDir],
79
80
  };
80
81
  }
81
82
 
@@ -535,7 +536,7 @@ RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding
535
536
  });
536
537
  }
537
538
 
538
- #pragma mark - fs.getEnvionmentDirs
539
+ #pragma mark - fs.getEnvironmentDirs
539
540
  RCT_EXPORT_METHOD(getEnvironmentDirs:(RCTResponseSenderBlock) callback)
540
541
  {
541
542
 
@@ -54,6 +54,7 @@
54
54
  + (NSString *) getMovieDir;
55
55
  + (NSString *) getMusicDir;
56
56
  + (NSString *) getPictureDir;
57
+ + (NSString *) getApplicationSupportDir;
57
58
  + (NSString *) getTempPath;
58
59
  + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext;
59
60
  + (NSString *) getPathOfAsset:(NSString *)assetURI;
@@ -124,6 +124,10 @@ NSMutableDictionary *fileStreams = nil;
124
124
  return [NSSearchPathForDirectoriesInDomains(NSPicturesDirectory, NSUserDomainMask, YES) firstObject];
125
125
  }
126
126
 
127
+ + (NSString *) getApplicationSupportDir {
128
+ return [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
129
+ }
130
+
127
131
  + (NSString *) getTempPath {
128
132
 
129
133
  return NSTemporaryDirectory();
@@ -0,0 +1,33 @@
1
+ import {NativeModules} from 'react-native';
2
+ import type {ReactNativeBlobUtilNative, filedescriptor} from "types";
3
+
4
+ const ReactNativeBlobUtil: ReactNativeBlobUtilNative = NativeModules.ReactNativeBlobUtil;
5
+
6
+ function createMediafile(fd: filedescriptor, mediatype: string): Promise {
7
+ if ((!'parentFolder' in fd)) fd['parentFolder'] = '';
8
+ return ReactNativeBlobUtil.createMediaFile(fd, mediatype);
9
+ }
10
+
11
+ function writeToMediafile(uri: string, path: string) {
12
+ return ReactNativeBlobUtil.writeToMediaFile(uri, path);
13
+ }
14
+
15
+ function copyToInternal(contenturi: string, destpath: string) {
16
+ return ReactNativeBlobUtil.copyToInternal(contenturi, destpath);
17
+ }
18
+
19
+ function getBlob(contenturi: string, encoding: string) {
20
+ return ReactNativeBlobUtil.getBlob(contenturi, encoding);
21
+ }
22
+
23
+ function copyToMediaStore(fd: filedescriptor, mediatype: string, path: string) {
24
+ return ReactNativeBlobUtil.copyToMediaStore(fd, mediatype, path);
25
+ }
26
+
27
+ export default {
28
+ createMediafile,
29
+ writeToMediafile,
30
+ copyToInternal,
31
+ getBlob,
32
+ copyToMediaStore
33
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.13.18",
3
+ "version": "0.14.0",
4
4
  "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -67,5 +67,5 @@ try {
67
67
  '\033[95mreact-native-blob-util\033[97m link \033[91mFAILED \033[97m\nCould not automatically link package :'+
68
68
  err.stack +
69
69
  'please follow the instructions to manually link the library : ' +
70
- '\033[4mhttps://github.com/joltup/react-native-blob-util/wiki/Manually-Link-Package\n')
70
+ '\033[4mhttps://github.com/RonRadtke/react-native-blob-util/wiki/Manually-Link-Package\n')
71
71
  }
package/types.js CHANGED
@@ -64,3 +64,6 @@ export type ReactNativeBlobUtilStream = {
64
64
  _onEnd : () => void,
65
65
  _onError : () => void,
66
66
  }
67
+
68
+
69
+ export type filedescriptor = { path: string, parentFolder: string, mimeType: string }