react-native-blob-util 0.17.0 → 0.17.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/README.md CHANGED
@@ -12,7 +12,7 @@ The project will be continued in this repository. React-Native-Blob-Util is full
12
12
 
13
13
  # Version Compatibility Warning
14
14
 
15
- react-native-blob-util version **0.17.0** and up is only compatible with react native **0.64** and up.
15
+ react-native-blob-util version **0.17.0** and up is only compatible with react native **0.65** and up.
16
16
 
17
17
  react-native-blob-util version **0.10.16** and up is only compatible with react native **0.60** and up.
18
18
 
@@ -59,6 +59,10 @@ android {
59
59
  proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
60
60
  }
61
61
  }
62
+ compileOptions {
63
+ sourceCompatibility JavaVersion.VERSION_1_8
64
+ targetCompatibility JavaVersion.VERSION_1_8
65
+ }
62
66
  lintOptions {
63
67
  abortOnError false
64
68
  }
@@ -157,4 +161,4 @@ afterEvaluate { project ->
157
161
  }
158
162
  }
159
163
  }
160
- }
164
+ }
@@ -355,7 +355,11 @@ class ReactNativeBlobUtilFS {
355
355
  } else {
356
356
  res.put("SDCardApplicationDir", "");
357
357
  }
358
+ } else {
359
+ res.put("SDCardDir", "");
360
+ res.put("SDCardApplicationDir", "");
358
361
  }
362
+
359
363
  res.put("MainBundleDir", ctx.getApplicationInfo().dataDir);
360
364
 
361
365
  // TODO Change me with the correct path
@@ -376,7 +380,20 @@ class ReactNativeBlobUtilFS {
376
380
  static Map<String, Object> getLegacySystemfolders(ReactApplicationContext ctx) {
377
381
  Map<String, Object> res = new HashMap<>();
378
382
 
379
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) return ReactNativeBlobUtilFS.getSystemfolders(ctx);
383
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
384
+ res = ReactNativeBlobUtilFS.getSystemfolders(ctx);
385
+
386
+ // Include legacy folders anyway, since on the new arch compatibility between the spec and the turbomodule is enforced
387
+ res.put("LegacyDCIMDir", "");
388
+ res.put("LegacyPictureDir", "");
389
+ res.put("LegacyMusicDir", "");
390
+ res.put("LegacyDownloadDir", "");
391
+ res.put("LegacyMovieDir", "");
392
+ res.put("LegacyRingtoneDir", "");
393
+ res.put("LegacySDCardDir", "");
394
+
395
+ return res;
396
+ }
380
397
 
381
398
  res.put("LegacyDCIMDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath());
382
399
  res.put("LegacyPictureDir", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
@@ -388,6 +405,8 @@ class ReactNativeBlobUtilFS {
388
405
  String state = Environment.getExternalStorageState();
389
406
  if (state.equals(Environment.MEDIA_MOUNTED)) {
390
407
  res.put("LegacySDCardDir", Environment.getExternalStorageDirectory().getAbsolutePath());
408
+ } else {
409
+ res.put("LegacySDCardDir", "");
391
410
  }
392
411
 
393
412
  return res;
@@ -155,8 +155,8 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
155
155
  }
156
156
 
157
157
  public static void cancelTask(String taskId) {
158
- if (taskTable.containsKey(taskId)) {
159
- Call call = taskTable.get(taskId);
158
+ Call call = taskTable.get(taskId);
159
+ if (call != null) {
160
160
  call.cancel();
161
161
  taskTable.remove(taskId);
162
162
  }
@@ -27,7 +27,7 @@ public class MimeType {
27
27
  public static String getFullFileName(String name, String mimeType) {
28
28
  // Prior to API 29, MimeType.BINARY_FILE has no file extension
29
29
  String ext = MimeType.getExtensionFromMimeType(mimeType);
30
- if ((ext == null || ext.isEmpty()) || name.endsWith("." + "ext")) return name;
30
+ if ((ext == null || ext.isEmpty()) || name.endsWith("." + ext)) return name;
31
31
  else {
32
32
  String fn = name + "." + ext;
33
33
  if (fn.endsWith(".")) return StringUtils.stripEnd(fn, ".");
@@ -0,0 +1,10 @@
1
+ const CANCELED_FETCH_ERROR_NAME = 'ReactNativeBlobUtilCanceledFetch'
2
+
3
+ class CanceledFetchError extends Error {
4
+ constructor(message) {
5
+ super(message);
6
+ this.name = CANCELED_FETCH_ERROR_NAME
7
+ }
8
+ }
9
+
10
+ export default CanceledFetchError
@@ -18,6 +18,14 @@ export interface Spec extends TurboModule {
18
18
  SDCardDir: string,
19
19
  SDCardApplicationDir: string,
20
20
  DCIMDir: string,
21
+ // Android Only Legacy Constants
22
+ LegacyDCIMDir: string,
23
+ LegacyPictureDir: string,
24
+ LegacyMusicDir: string,
25
+ LegacyDownloadDir: string,
26
+ LegacyMovieDir: string,
27
+ LegacyRingtoneDir: string,
28
+ LegacySDCardDir: string,
21
29
  |};
22
30
 
23
31
  +fetchBlobForm: (options: Object, taskId: string, method: string, url: string, headers: Object, form: Array<any>, callback: (value: Array<any>) => void) => void;
package/fetch.js CHANGED
@@ -4,6 +4,7 @@ import fs from "./fs";
4
4
  import getUUID from "./utils/uuid";
5
5
  import {DeviceEventEmitter} from "react-native";
6
6
  import {FetchBlobResponse} from "./class/ReactNativeBlobUtilBlobResponse";
7
+ import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
7
8
  import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
8
9
 
9
10
  const emitter = DeviceEventEmitter;
@@ -328,7 +329,7 @@ export function fetch(...args: any): Promise {
328
329
  subscriptionUpload.remove();
329
330
  stateEvent.remove();
330
331
  ReactNativeBlobUtil.cancelRequest(taskId, fn);
331
- promiseReject(new Error("canceled"));
332
+ promiseReject(new CanceledFetchError("canceled"));
332
333
  };
333
334
  promise.taskId = taskId;
334
335
 
package/fs.js CHANGED
@@ -26,6 +26,13 @@ const dirs = {
26
26
  MainBundleDir: constants.MainBundleDir,
27
27
  LibraryDir: constants.LibraryDir,
28
28
  ApplicationSupportDir: constants.ApplicationSupportDir,
29
+
30
+ LegacyPictureDir: constants.LegacyPictureDir,
31
+ LegacyMusicDir: constants.LegacyMusicDir,
32
+ LegacyMovieDir: constants.LegacyMovieDir,
33
+ LegacyDownloadDir: constants.LegacyDownloadDir,
34
+ LegacyDCIMDir: constants.LegacyDCIMDir,
35
+ LegacySDCardDir: constants.LegacySDCardDir, // Depracated
29
36
  };
30
37
 
31
38
  function addCode(code: string, error: Error): Error {
package/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export const ReactNativeBlobUtil: ReactNativeBlobUtilStatic;
7
7
  export type ReactNativeBlobUtil = ReactNativeBlobUtilStatic;
8
8
  export default ReactNativeBlobUtil;
9
9
  import {filedescriptor} from './types';
10
+ import CanceledFetchError from './class/ReactNativeBlobUtilCanceledFetchError'
10
11
 
11
12
  interface ReactNativeBlobUtilStatic {
12
13
  fetch(method: Methods, url: string, headers?: { [key: string]: string }, body?: any
@@ -29,6 +30,7 @@ interface ReactNativeBlobUtilStatic {
29
30
  polyfill: Polyfill;
30
31
  // this require external module https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/oboe
31
32
  JSONStream: any;
33
+ CanceledFetchError: CanceledFetchError
32
34
  }
33
35
 
34
36
  export interface Polyfill {
@@ -555,6 +557,12 @@ export interface IOSApi {
555
557
  * @param {string} scheme URI scheme that needs to support, optional
556
558
  */
557
559
  presentPreview(path: string, scheme?: string): void;
560
+
561
+ /**
562
+ * Marks the file to be excluded from icloud/itunes backup. Works recursively if path is to a directory
563
+ * @param {string} path Path to a file or directory to mark to be excluded.
564
+ */
565
+ excludeFromBackupKey(path: string): Promise<void>;
558
566
  }
559
567
 
560
568
  export interface AndroidDownloadOption {
package/index.js CHANGED
@@ -15,6 +15,7 @@ import ios from './ios';
15
15
  import JSONStream from './json-stream';
16
16
  import {config, fetch} from './fetch';
17
17
  import URIUtil from "./utils/uri";
18
+ import CanceledFetchError from "./class/ReactNativeBlobUtilCanceledFetchError";
18
19
 
19
20
  const {
20
21
  ReactNativeBlobUtilSession,
@@ -70,5 +71,6 @@ export default {
70
71
  wrap,
71
72
  polyfill,
72
73
  JSONStream,
73
- MediaCollection
74
+ MediaCollection,
75
+ CanceledFetchError
74
76
  };
package/index.web.js ADDED
@@ -0,0 +1 @@
1
+ export default {};
@@ -12,7 +12,7 @@
12
12
  #import "ReactNativeBlobUtilProgress.h"
13
13
 
14
14
  #if RCT_NEW_ARCH_ENABLED
15
- #import "ReactNativeBlobUtilSpec.h"
15
+ #import <ReactNativeBlobUtilSpec/ReactNativeBlobUtilSpec.h>
16
16
  #endif
17
17
 
18
18
  __strong RCTEventDispatcher * eventDispatcherRef;
@@ -95,6 +95,14 @@ RCT_EXPORT_MODULE();
95
95
  @"SDCardDir": @"",
96
96
  @"SDCardApplicationDir": @"",
97
97
  @"DCIMDir": @"",
98
+ // Android only legacy constants
99
+ @"LegacyDCIMDir": @"",
100
+ @"LegacyPictureDir": @"",
101
+ @"LegacyMusicDir": @"",
102
+ @"LegacyDownloadDir": @"",
103
+ @"LegacyMovieDir": @"",
104
+ @"LegacyRingtoneDir": @"",
105
+ @"LegacySDCardDir": @"",
98
106
  };
99
107
  }
100
108
 
@@ -677,7 +685,7 @@ RCT_EXPORT_METHOD(hash:(NSString *)path
677
685
  }
678
686
 
679
687
  #pragma mark - fs.readStream
680
- RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId)
688
+ RCT_EXPORT_METHOD(readStream:(NSString *)path encoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId)
681
689
  {
682
690
  if(bufferSize == 0) {
683
691
  if([[encoding lowercaseString] isEqualToString:@"base64"])
@@ -902,7 +910,7 @@ RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
902
910
  }
903
911
  - (void)copyToMediaStore:(NSDictionary *)filedata
904
912
  mt:(NSString *) mt
905
- path:(NSString *)
913
+ path:(NSString *) path
906
914
  resolve:(RCTPromiseResolveBlock)resolve
907
915
  reject:(RCTPromiseRejectBlock)reject
908
916
  {
@@ -955,7 +963,6 @@ RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
955
963
  reject(@"ENOT_SUPPORTED", @"This method is not supported on iOS", nil);
956
964
  }
957
965
 
958
-
959
966
  # pragma mark - New Architecture
960
967
  #if RCT_NEW_ARCH_ENABLED
961
968
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
@@ -411,9 +411,9 @@ NSMutableDictionary *fileStreams = nil;
411
411
  [fileHandle closeFile];
412
412
  }
413
413
  else {
414
- if (![content writeToFile:path atomically:YES]) {
414
+ if (![content writeToFile:path options:NSDataWritingAtomic error:&err]) {
415
415
  fm = nil;
416
- return reject(@"EUNSPECIFIED", [NSString stringWithFormat:@"File '%@' could not be written.", path], nil);
416
+ return reject(@"EUNSPECIFIED", [NSString stringWithFormat:@"File '%@' could not be written; error: %@", path, [err description]], err);
417
417
  }
418
418
  }
419
419
  fm = nil;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.17.0",
3
+ "version": "0.17.2",
4
4
  "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5
- "main": "index.js",
5
+ "main": "index",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
package/polyfill/Fetch.js CHANGED
@@ -40,7 +40,10 @@ class ReactNativeBlobUtilFetchPolyfill {
40
40
  log.verbose('convert FormData to blob body');
41
41
  promise = Blob.build(body).then((b) => {
42
42
  blobCache = b;
43
- options.headers['Content-Type'] = 'multipart/form-data;boundary=' + b.multipartBoundary;
43
+
44
+ const contentType = 'multipart/form-data;boundary=' + b.multipartBoundary
45
+ options.headers['Content-Type'] = contentType;
46
+ options.headers['content-type'] = contentType;
44
47
  return Promise.resolve(URIUtil.wrap(b._ref));
45
48
  });
46
49
  }