react-native-blob-util 0.16.4 → 0.17.1

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 (78) hide show
  1. package/.eslintrc.js +29 -3
  2. package/Migration.md +41 -0
  3. package/README.md +13 -6
  4. package/android/build.gradle +19 -1
  5. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilBody.java +6 -6
  6. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +12 -8
  7. package/android/src/main/java/com/ReactNativeBlobUtil/{ReactNativeBlobUtil.java → ReactNativeBlobUtilImpl.java} +19 -78
  8. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilMediaCollection.java +5 -5
  9. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilPackage.java +31 -21
  10. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +22 -21
  11. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java +6 -6
  12. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilUtils.java +2 -2
  13. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +1 -1
  14. package/android/src/newarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +281 -0
  15. package/android/src/oldarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +242 -0
  16. package/android.js +2 -3
  17. package/class/ReactNativeBlobUtilFile.js +1 -13
  18. package/class/ReactNativeBlobUtilReadStream.js +1 -2
  19. package/class/ReactNativeBlobUtilSession.js +1 -2
  20. package/class/ReactNativeBlobUtilWriteStream.js +1 -3
  21. package/codegenSpecs/NativeBlobUtils.js +77 -0
  22. package/fetch.js +2 -2
  23. package/fs.js +22 -22
  24. package/index.d.ts +6 -0
  25. package/index.js +2 -2
  26. package/index.web.js +1 -0
  27. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +10 -1
  28. package/ios/ReactNativeBlobUtil/{ReactNativeBlobUtil.m → ReactNativeBlobUtil.mm} +334 -41
  29. package/ios/{ReactNativeBlobUtilConst.m → ReactNativeBlobUtilConst.mm} +0 -0
  30. package/ios/ReactNativeBlobUtilFS.h +5 -5
  31. package/ios/{ReactNativeBlobUtilFS.m → ReactNativeBlobUtilFS.mm} +32 -26
  32. package/ios/{ReactNativeBlobUtilFileTransformer.m → ReactNativeBlobUtilFileTransformer.mm} +0 -0
  33. package/ios/ReactNativeBlobUtilNetwork.h +2 -2
  34. package/ios/{ReactNativeBlobUtilNetwork.m → ReactNativeBlobUtilNetwork.mm} +15 -17
  35. package/ios/{ReactNativeBlobUtilProgress.m → ReactNativeBlobUtilProgress.mm} +4 -4
  36. package/ios/{ReactNativeBlobUtilReqBuilder.m → ReactNativeBlobUtilReqBuilder.mm} +4 -4
  37. package/ios/ReactNativeBlobUtilRequest.h +4 -2
  38. package/ios/{ReactNativeBlobUtilRequest.m → ReactNativeBlobUtilRequest.mm} +16 -11
  39. package/ios.js +2 -3
  40. package/mediacollection.js +2 -4
  41. package/package.json +7 -2
  42. package/react-native-blob-util.podspec +21 -1
  43. package/examples/ReactNativeBlobUtil/.buckconfig +0 -6
  44. package/examples/ReactNativeBlobUtil/.eslintrc.js +0 -4
  45. package/examples/ReactNativeBlobUtil/.prettierrc.js +0 -6
  46. package/examples/ReactNativeBlobUtil/App.js +0 -698
  47. package/examples/ReactNativeBlobUtil/index.js +0 -9
  48. package/examples/ReactNativeBlobUtil/metro.config.js +0 -27
  49. package/examples/ReactNativeBlobUtil/package.json +0 -31
  50. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/App.cpp +0 -80
  51. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/App.h +0 -20
  52. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/App.idl +0 -3
  53. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/App.xaml +0 -10
  54. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/LockScreenLogo.scale-200.png +0 -0
  55. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/SplashScreen.scale-200.png +0 -0
  56. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/Square150x150Logo.scale-200.png +0 -0
  57. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/Square44x44Logo.scale-200.png +0 -0
  58. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/Square44x44Logo.targetsize-24_altform-unplated.png +0 -0
  59. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/StoreLogo.png +0 -0
  60. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Assets/Wide310x150Logo.scale-200.png +0 -0
  61. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/AutolinkedNativeModules.g.cpp +0 -18
  62. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/AutolinkedNativeModules.g.h +0 -10
  63. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/AutolinkedNativeModules.g.targets +0 -11
  64. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/MainPage.cpp +0 -24
  65. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/MainPage.h +0 -21
  66. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/MainPage.idl +0 -8
  67. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/MainPage.xaml +0 -16
  68. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/Package.appxmanifest +0 -50
  69. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/PropertySheet.props +0 -16
  70. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/ReactNativeBlobUtilWin.vcxproj +0 -196
  71. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/ReactNativeBlobUtilWin.vcxproj.filters +0 -65
  72. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/ReactNativeBlobUtilWin_TemporaryKey.pfx +0 -0
  73. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/ReactPackageProvider.cpp +0 -18
  74. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/ReactPackageProvider.h +0 -15
  75. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/packages.config +0 -5
  76. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/pch.cpp +0 -1
  77. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin/pch.h +0 -26
  78. package/examples/ReactNativeBlobUtil/windows/ReactNativeBlobUtilWin.sln +0 -207
@@ -18,13 +18,13 @@
18
18
  #import "RCTBridgeModule.h"
19
19
  #endif
20
20
 
21
- @import AssetsLibrary;
21
+ #import <AssetsLibrary/AssetsLibrary.h>
22
22
 
23
23
  @interface ReactNativeBlobUtilFS : NSObject <NSStreamDelegate> {
24
24
  NSOutputStream * outStream;
25
25
  NSInputStream * inStream;
26
26
  RCTResponseSenderBlock callback;
27
- RCTBridge * bridge;
27
+ RCTEventDispatcher * eventDispatcher;
28
28
  Boolean isOpen;
29
29
  NSString * encoding;
30
30
  int bufferSize;
@@ -37,7 +37,7 @@
37
37
  @property (nonatomic) NSOutputStream * _Nullable outStream;
38
38
  @property (nonatomic) NSInputStream * _Nullable inStream;
39
39
  @property (strong, nonatomic) RCTResponseSenderBlock callback;
40
- @property (nonatomic) RCTBridge * bridge;
40
+ @property (nonatomic) RCTEventDispatcher * eventDispatcher;
41
41
  @property (nonatomic) NSString * encoding;
42
42
  @property (nonatomic) NSString * taskId;
43
43
  @property (nonatomic) NSString * path;
@@ -85,13 +85,13 @@
85
85
  rejecter:(RCTPromiseRejectBlock)reject;
86
86
  //+ (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
87
87
  + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest;
88
- + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId bridgeRef:(RCTBridge *)bridgeRef;
88
+ + (void) readStream:(NSString *)uri encoding:(NSString * )encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId eventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef;
89
89
  + (void) df:(RCTResponseSenderBlock)callback;
90
90
 
91
91
  // constructor
92
92
  - (id) init;
93
93
  - (id)initWithCallback:(RCTResponseSenderBlock)callback;
94
- - (id)initWithBridgeRef:(RCTBridge *)bridgeRef;
94
+ - (id)initWithEventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef;
95
95
 
96
96
  // file stream
97
97
  - (void) openWithDestination;
@@ -11,7 +11,7 @@
11
11
  #import "ReactNativeBlobUtilFS.h"
12
12
  #import "ReactNativeBlobUtilConst.h"
13
13
  #import "ReactNativeBlobUtilFileTransformer.h"
14
- @import AssetsLibrary;
14
+ #import <AssetsLibrary/AssetsLibrary.h>
15
15
 
16
16
  #import <CommonCrypto/CommonDigest.h>
17
17
 
@@ -58,14 +58,14 @@ NSMutableDictionary *fileStreams = nil;
58
58
  return self;
59
59
  }
60
60
 
61
- - (id)initWithBridgeRef:(RCTBridge *)bridgeRef {
61
+ - (id)initWithEventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef {
62
62
  self = [super init];
63
- self.bridge = bridgeRef;
63
+ self.eventDispatcher = eventDispatcherRef;
64
64
  return self;
65
65
  }
66
66
 
67
67
  // static member getter
68
- + (NSArray *) getFileStreams {
68
+ + (NSDictionary *) getFileStreams {
69
69
 
70
70
  if(fileStreams == nil)
71
71
  fileStreams = [[NSMutableDictionary alloc] init];
@@ -160,11 +160,11 @@ NSMutableDictionary *fileStreams = nil;
160
160
  bufferSize:(int)bufferSize
161
161
  tick:(int)tick
162
162
  streamId:(NSString *)streamId
163
- bridgeRef:(RCTBridge *)bridgeRef
163
+ eventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef
164
164
  {
165
165
  [[self class] getPathFromUri:uri completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
166
166
 
167
- __block RCTEventDispatcher * event = bridgeRef.eventDispatcher;
167
+ __block RCTEventDispatcher * event = eventDispatcherRef;
168
168
  __block int read = 0;
169
169
  __block int backoff = tick *1000;
170
170
  __block int chunkSize = bufferSize;
@@ -508,7 +508,8 @@ NSMutableDictionary *fileStreams = nil;
508
508
  __block Byte * buffer;
509
509
  if(asset != nil)
510
510
  {
511
- buffer = malloc(asset.size);
511
+ int size = asset.size;
512
+ buffer = (Byte *)malloc(size);
512
513
  [asset getBytes:buffer fromOffset:0 length:asset.size error:&err];
513
514
  if(err != nil)
514
515
  {
@@ -516,7 +517,7 @@ NSMutableDictionary *fileStreams = nil;
516
517
  free(buffer);
517
518
  return;
518
519
  }
519
- fileContent = [NSData dataWithBytes:buffer length:asset.size];
520
+ fileContent = [NSData dataWithBytes:buffer length:size];
520
521
  free(buffer);
521
522
  }
522
523
  else
@@ -555,21 +556,25 @@ NSMutableDictionary *fileStreams = nil;
555
556
  if([[encoding lowercaseString] isEqualToString:@"utf8"])
556
557
  {
557
558
  NSString * utf8 = [[NSString alloc] initWithData:fileContent encoding:NSUTF8StringEncoding];
558
- if(utf8 == nil)
559
- onComplete([[NSString alloc] initWithData:fileContent encoding:NSISOLatin1StringEncoding], nil, nil);
560
- else
561
- onComplete(utf8, nil, nil);
559
+ if(utf8 == nil) {
560
+ NSString * latin1 = [[NSString alloc] initWithData:fileContent encoding:NSISOLatin1StringEncoding];
561
+ NSData * latin1Data = [latin1 dataUsingEncoding:NSISOLatin1StringEncoding];
562
+ onComplete(latin1Data, nil, nil);
563
+ } else {
564
+ onComplete(fileContent, nil, nil);
565
+ }
562
566
  }
563
567
  else if ([[encoding lowercaseString] isEqualToString:@"base64"]) {
564
- onComplete([fileContent base64EncodedStringWithOptions:0], nil, nil);
568
+ NSString * base64String = [fileContent base64EncodedStringWithOptions:0];
569
+ onComplete([[NSData alloc] initWithBase64EncodedString:base64String options:0], nil, nil);
565
570
  }
566
571
  else if ([[encoding lowercaseString] isEqualToString:@"ascii"]) {
567
572
  NSMutableArray * resultArray = [NSMutableArray array];
568
- char * bytes = [fileContent bytes];
573
+ char * bytes = (char *)[fileContent bytes];
569
574
  for(int i=0;i<[fileContent length];i++) {
570
575
  [resultArray addObject:[NSNumber numberWithChar:bytes[i]]];
571
576
  }
572
- onComplete(resultArray, nil, nil);
577
+ onComplete((NSData *)resultArray, nil, nil);
573
578
  }
574
579
  }
575
580
  else
@@ -690,11 +695,11 @@ NSMutableDictionary *fileStreams = nil;
690
695
  if([fm fileExistsAtPath:path isDirectory:&isDir] == NO) {
691
696
  return nil;
692
697
  }
693
- NSDictionary * info = [fm attributesOfItemAtPath:path error:&error];
694
- NSString * size = [NSString stringWithFormat:@"%d", [info fileSize]];
698
+ NSDictionary * info = [fm attributesOfItemAtPath:path error:error];
699
+ NSString * size = [NSString stringWithFormat:@"%llu", [info fileSize]];
695
700
  NSString * filename = [path lastPathComponent];
696
701
  NSDate * lastModified;
697
- [[NSURL fileURLWithPath:path] getResourceValue:&lastModified forKey:NSURLContentModificationDateKey error:&error];
702
+ [[NSURL fileURLWithPath:path] getResourceValue:&lastModified forKey:NSURLContentModificationDateKey error:error];
698
703
  return @{
699
704
  @"size" : size,
700
705
  @"filename" : filename,
@@ -759,7 +764,7 @@ NSMutableDictionary *fileStreams = nil;
759
764
  NSUInteger left = [decodedData length];
760
765
  NSUInteger nwr = 0;
761
766
  do {
762
- nwr = [self.outStream write:[decodedData bytes] maxLength:left];
767
+ nwr = [self.outStream write:(const uint8_t *)[decodedData bytes] maxLength:left];
763
768
  if (-1 == nwr) break;
764
769
  left -= nwr;
765
770
  } while (left > 0);
@@ -773,7 +778,7 @@ NSMutableDictionary *fileStreams = nil;
773
778
  NSUInteger left = [chunk length];
774
779
  NSUInteger nwr = 0;
775
780
  do {
776
- nwr = [self.outStream write:[chunk bytes] maxLength:left];
781
+ nwr = [self.outStream write:(const uint8_t *)[chunk bytes] maxLength:left];
777
782
  if (-1 == nwr) break;
778
783
  left -= nwr;
779
784
  } while (left > 0);
@@ -826,7 +831,7 @@ NSMutableDictionary *fileStreams = nil;
826
831
  long max = MIN(size, [end longValue]);
827
832
 
828
833
  if(![fm fileExistsAtPath:dest]) {
829
- if(![fm createFileAtPath:dest contents:@"" attributes:nil]) {
834
+ if(![fm createFileAtPath:dest contents:[NSData new] attributes:nil]) {
830
835
  return reject(@"ENOENT", [NSString stringWithFormat:@"File '%@' does not exist and could not be created", path], nil);
831
836
  }
832
837
  }
@@ -842,7 +847,7 @@ NSMutableDictionary *fileStreams = nil;
842
847
  }
843
848
  else
844
849
  {
845
- NSLog(@"read chunk %lu", 10240);
850
+ NSLog(@"read chunk %d", 10240);
846
851
  chunkSize = 10240;
847
852
  chunk = [handle readDataOfLength:10240];
848
853
  }
@@ -850,7 +855,7 @@ NSMutableDictionary *fileStreams = nil;
850
855
  break;
851
856
  long remain = expected - read;
852
857
 
853
- [os write:[chunk bytes] maxLength:chunkSize];
858
+ [os write:(const uint8_t *)[chunk bytes] maxLength:chunkSize];
854
859
  read += [chunk length];
855
860
  }
856
861
  [handle closeFile];
@@ -868,19 +873,20 @@ NSMutableDictionary *fileStreams = nil;
868
873
  long max = MIN(size, [end longValue]);
869
874
 
870
875
  while(read < expected) {
871
- uint8_t * chunk[10240];
876
+ uint8_t chunk[10240];
877
+ uint8_t * pointerToChunk = &chunk[0];
872
878
  long chunkSize = 0;
873
879
  if([start longValue] + read + 10240 > max)
874
880
  {
875
881
  NSLog(@"read chunk %lu", max - read - [start longValue]);
876
882
  chunkSize = max - read - [start longValue];
877
- chunkRead = [asset getBytes:chunk fromOffset:[start longValue] + read length:chunkSize error:nil];
883
+ chunkRead = [asset getBytes:pointerToChunk fromOffset:[start longValue] + read length:chunkSize error:nil];
878
884
  }
879
885
  else
880
886
  {
881
887
  NSLog(@"read chunk %lu", 10240);
882
888
  chunkSize = 10240;
883
- chunkRead = [asset getBytes:chunk fromOffset:[start longValue] + read length:chunkSize error:nil];
889
+ chunkRead = [asset getBytes:pointerToChunk fromOffset:[start longValue] + read length:chunkSize error:nil];
884
890
  }
885
891
  if( chunkRead <= 0)
886
892
  break;
@@ -30,12 +30,12 @@
30
30
 
31
31
  + (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance;
32
32
  + (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
33
- + (void) emitExpiredTasks;
33
+ + (void) emitExpiredTasks:(RCTEventDispatcher *) eventDispatcher;
34
34
 
35
35
  - (nullable id) init;
36
36
  - (void) sendRequest:(NSDictionary * _Nullable )options
37
37
  contentLength:(long)contentLength
38
- bridge:(RCTBridge * _Nullable)bridgeRef
38
+ eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
39
39
  taskId:(NSString * _Nullable)taskId
40
40
  withRequest:(NSURLRequest * _Nullable)req
41
41
  callback:(_Nullable RCTResponseSenderBlock) callback;
@@ -10,7 +10,6 @@
10
10
  #import <Foundation/Foundation.h>
11
11
  #import "ReactNativeBlobUtilNetwork.h"
12
12
 
13
- #import "ReactNativeBlobUtil.h"
14
13
  #import "ReactNativeBlobUtilConst.h"
15
14
  #import "ReactNativeBlobUtilProgress.h"
16
15
 
@@ -49,14 +48,14 @@ static void initialize_tables() {
49
48
  self = [super init];
50
49
  if (self) {
51
50
  self.requestsTable = [NSMapTable mapTableWithKeyOptions:NSMapTableStrongMemory valueOptions:NSMapTableWeakMemory];
52
-
51
+
53
52
  self.taskQueue = [[NSOperationQueue alloc] init];
54
53
  self.taskQueue.qualityOfService = NSQualityOfServiceUtility;
55
54
  self.taskQueue.maxConcurrentOperationCount = 10;
56
55
  self.rebindProgressDict = [NSMutableDictionary dictionary];
57
56
  self.rebindUploadProgressDict = [NSMutableDictionary dictionary];
58
57
  }
59
-
58
+
60
59
  return self;
61
60
  }
62
61
 
@@ -67,13 +66,13 @@ static void initialize_tables() {
67
66
  dispatch_once(&onceToken, ^{
68
67
  _sharedInstance = [[self alloc] init];
69
68
  });
70
-
69
+
71
70
  return _sharedInstance;
72
71
  }
73
72
 
74
73
  - (void) sendRequest:(__weak NSDictionary * _Nullable )options
75
74
  contentLength:(long) contentLength
76
- bridge:(RCTBridge * _Nullable)bridgeRef
75
+ eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
77
76
  taskId:(NSString * _Nullable)taskId
78
77
  withRequest:(__weak NSURLRequest * _Nullable)req
79
78
  callback:(_Nullable RCTResponseSenderBlock) callback
@@ -81,12 +80,12 @@ static void initialize_tables() {
81
80
  ReactNativeBlobUtilRequest *request = [[ReactNativeBlobUtilRequest alloc] init];
82
81
  [request sendRequest:options
83
82
  contentLength:contentLength
84
- bridge:bridgeRef
83
+ eventDispatcher:eventDispatcherRef
85
84
  taskId:taskId
86
85
  withRequest:req
87
86
  taskOperationQueue:self.taskQueue
88
87
  callback:callback];
89
-
88
+
90
89
  @synchronized([ReactNativeBlobUtilNetwork class]) {
91
90
  [self.requestsTable setObject:request forKey:taskId];
92
91
  [self checkProgressConfigForTask:taskId];
@@ -100,7 +99,7 @@ static void initialize_tables() {
100
99
  [self enableProgressReport:taskId config:downloadConfig];
101
100
  [self.rebindProgressDict removeObjectForKey:taskId];
102
101
  }
103
-
102
+
104
103
  //reconfig uploadProgress
105
104
  ReactNativeBlobUtilProgress *uploadConfig = self.rebindUploadProgressDict[taskId];
106
105
  if (uploadConfig != nil) {
@@ -138,11 +137,11 @@ static void initialize_tables() {
138
137
  - (void) cancelRequest:(NSString *)taskId
139
138
  {
140
139
  NSURLSessionDataTask * task;
141
-
140
+
142
141
  @synchronized ([ReactNativeBlobUtilNetwork class]) {
143
142
  task = [self.requestsTable objectForKey:taskId].task;
144
143
  }
145
-
144
+
146
145
  if (task && task.state == NSURLSessionTaskStateRunning) {
147
146
  [task cancel];
148
147
  }
@@ -155,25 +154,24 @@ static void initialize_tables() {
155
154
  for (NSString * key in headers) {
156
155
  [mheaders setValue:[headers valueForKey:key] forKey:[key lowercaseString]];
157
156
  }
158
-
157
+
159
158
  return mheaders;
160
159
  }
161
160
 
162
161
  // #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
163
- + (void) emitExpiredTasks
162
+ + (void) emitExpiredTasks:(RCTEventDispatcher *)eventDispatcher
164
163
  {
165
164
  @synchronized ([ReactNativeBlobUtilNetwork class]){
166
165
  NSEnumerator * emu = [expirationTable keyEnumerator];
167
166
  NSString * key;
168
-
167
+
169
168
  while ((key = [emu nextObject]))
170
169
  {
171
- RCTBridge * bridge = [ReactNativeBlobUtil getRCTBridge];
172
170
  id args = @{ @"taskId": key };
173
- [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
174
-
171
+ [eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
172
+
175
173
  }
176
-
174
+
177
175
  // clear expired task entries
178
176
  [expirationTable removeAllObjects];
179
177
  expirationTable = [[NSMapTable alloc] init];
@@ -32,25 +32,25 @@
32
32
 
33
33
  -(BOOL)shouldReport:(NSNumber *)nextProgress
34
34
  {
35
- BOOL * result = YES;
35
+ BOOL result = YES;
36
36
  float countF = [self.count floatValue];
37
37
  if(countF > 0 && [nextProgress floatValue] > 0)
38
38
  {
39
39
  result = (int)(floorf([nextProgress floatValue]*countF)) >= tick;
40
40
  }
41
-
41
+
42
42
  NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
43
43
  // NSTimeInterval is defined as double
44
44
  NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];
45
45
  float delta = [timeStampObj doubleValue] - lastTick;
46
- BOOL * shouldReport = delta > [self.interval doubleValue] && self.enable && result;
46
+ BOOL shouldReport = delta > [self.interval doubleValue] && self.enable && result;
47
47
  if(shouldReport)
48
48
  {
49
49
  tick++;
50
50
  lastTick = [timeStampObj doubleValue];
51
51
  }
52
52
  return shouldReport;
53
-
53
+
54
54
  }
55
55
 
56
56
 
@@ -53,7 +53,7 @@
53
53
  [[self class] buildFormBody:form boundary:boundary onComplete:^(NSData *formData, BOOL hasError) {
54
54
  if(hasError)
55
55
  {
56
- onComplete(nil, nil);
56
+ onComplete(nil, 0);
57
57
  }
58
58
  else
59
59
  {
@@ -117,11 +117,11 @@
117
117
  orgPath = [[NSURL URLWithString:orgPath] path];
118
118
  if([orgPath hasPrefix:AL_PREFIX])
119
119
  {
120
-
120
+
121
121
  [ReactNativeBlobUtilFS readFile:orgPath encoding:nil transformFile:false onComplete:^(id content, NSString* code, NSString * err) {
122
122
  if(err != nil)
123
123
  {
124
- onComplete(nil, nil);
124
+ onComplete(nil, 0);
125
125
  }
126
126
  else
127
127
  {
@@ -131,7 +131,7 @@
131
131
  onComplete(request, [((NSData *)content) length]);
132
132
  }
133
133
  }];
134
-
134
+
135
135
  return;
136
136
  }
137
137
  size = [[[NSFileManager defaultManager] attributesOfItemAtPath:orgPath error:nil] fileSize];
@@ -15,8 +15,10 @@
15
15
 
16
16
  #if __has_include(<React/RCTAssert.h>)
17
17
  #import <React/RCTBridgeModule.h>
18
+ #import <React/RCTEventDispatcher.h>
18
19
  #else
19
20
  #import "RCTBridgeModule.h"
21
+ #import "RCTEventDispatcher.h"
20
22
  #endif
21
23
 
22
24
  @interface ReactNativeBlobUtilRequest : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
@@ -27,7 +29,7 @@
27
29
  @property (nonatomic) BOOL isServerPush;
28
30
  @property (nullable, nonatomic) NSMutableData * respData;
29
31
  @property (nullable, strong, nonatomic) RCTResponseSenderBlock callback;
30
- @property (nullable, nonatomic) RCTBridge * bridge;
32
+ @property (nullable, nonatomic) RCTEventDispatcher * eventDispatcher;
31
33
  @property (nullable, nonatomic) NSDictionary * options;
32
34
  @property (nullable, nonatomic) NSError * error;
33
35
  @property (nullable, nonatomic) ReactNativeBlobUtilProgress *progressConfig;
@@ -36,7 +38,7 @@
36
38
 
37
39
  - (void) sendRequest:(NSDictionary * _Nullable )options
38
40
  contentLength:(long)contentLength
39
- bridge:(RCTBridge * _Nullable)bridgeRef
41
+ eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
40
42
  taskId:(NSString * _Nullable)taskId
41
43
  withRequest:(NSURLRequest * _Nullable)req
42
44
  taskOperationQueue:(NSOperationQueue * _Nonnull)operationQueue
@@ -15,6 +15,12 @@
15
15
 
16
16
  #import <CommonCrypto/CommonDigest.h>
17
17
 
18
+ #if __has_include(<React/RCTAssert.h>)
19
+ #import <React/RCTEventDispatcherProtocol.h>
20
+ #else
21
+ #import "RCTEventDispatcherProtocol.h"
22
+ #endif
23
+
18
24
 
19
25
  typedef NS_ENUM(NSUInteger, ResponseFormat) {
20
26
  UTF8,
@@ -47,7 +53,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
47
53
  @synthesize receivedBytes;
48
54
  @synthesize respData;
49
55
  @synthesize callback;
50
- @synthesize bridge;
56
+ @synthesize eventDispatcher;
51
57
  @synthesize options;
52
58
  @synthesize error;
53
59
 
@@ -67,7 +73,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
67
73
  // send HTTP request
68
74
  - (void) sendRequest:(__weak NSDictionary * _Nullable )options
69
75
  contentLength:(long) contentLength
70
- bridge:(RCTBridge * _Nullable)bridgeRef
76
+ eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
71
77
  taskId:(NSString * _Nullable)taskId
72
78
  withRequest:(__weak NSURLRequest * _Nullable)req
73
79
  taskOperationQueue:(NSOperationQueue * _Nonnull)operationQueue
@@ -76,7 +82,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
76
82
  self.taskId = taskId;
77
83
  self.respData = [[NSMutableData alloc] initWithLength:0];
78
84
  self.callback = callback;
79
- self.bridge = bridgeRef;
85
+ self.eventDispatcher = eventDispatcherRef;
80
86
  self.expectedBytes = 0;
81
87
  self.receivedBytes = 0;
82
88
  self.options = options;
@@ -207,7 +213,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
207
213
 
208
214
  if (self.isServerPush) {
209
215
  if (partBuffer) {
210
- [self.bridge.eventDispatcher
216
+ [self.eventDispatcher
211
217
  sendDeviceEventWithName:EVENT_SERVER_PUSH
212
218
  body:@{
213
219
  @"taskId": taskId,
@@ -263,8 +269,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
263
269
  [cookieStore setCookies:cookies forURL:response.URL mainDocumentURL:nil];
264
270
  }
265
271
  }
266
-
267
- [self.bridge.eventDispatcher
272
+ [self.eventDispatcher
268
273
  sendDeviceEventWithName: EVENT_STATE_CHANGE
269
274
  body:@{
270
275
  @"taskId": taskId,
@@ -342,7 +347,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
342
347
  // If we need to process the data, we defer writing into the file until the we have all the data, at which point
343
348
  // we can perform the processing and then write into the file
344
349
  if (respFile && ![self ShouldTransformFile]) {
345
- [writeStream write:[data bytes] maxLength:[data length]];
350
+ [writeStream write:(const uint8_t *)[data bytes] maxLength:[data length]];
346
351
  } else {
347
352
  [respData appendData:data];
348
353
  }
@@ -354,7 +359,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
354
359
  NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
355
360
 
356
361
  if ([self.progressConfig shouldReport:now]) {
357
- [self.bridge.eventDispatcher
362
+ [self.eventDispatcher
358
363
  sendDeviceEventWithName:EVENT_PROGRESS
359
364
  body:@{
360
365
  @"taskId": taskId,
@@ -362,7 +367,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
362
367
  @"total": [NSString stringWithFormat:@"%lld", (long long) expectedBytes],
363
368
  @"chunk": chunkString
364
369
  }
365
- ];
370
+ ];
366
371
  }
367
372
  }
368
373
 
@@ -407,7 +412,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
407
412
  } else {
408
413
  @try{
409
414
  NSData* transformedData = [fileTransformer onWriteFile:respData];
410
- [writeStream write:[transformedData bytes] maxLength:[transformedData length]];
415
+ [writeStream write:(const uint8_t *)[transformedData bytes] maxLength:[transformedData length]];
411
416
  } @catch(NSException * ex)
412
417
  {
413
418
  errMsg = [NSString stringWithFormat:@"Exception on File Transformer: '%@' ", [ex description]];
@@ -468,7 +473,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
468
473
  NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
469
474
 
470
475
  if ([self.uploadProgressConfig shouldReport:now]) {
471
- [self.bridge.eventDispatcher
476
+ [self.eventDispatcher
472
477
  sendDeviceEventWithName:EVENT_PROGRESS_UPLOAD
473
478
  body:@{
474
479
  @"taskId": taskId,
package/ios.js CHANGED
@@ -2,9 +2,8 @@
2
2
  // Use of this source code is governed by a MIT-style license that can be
3
3
  // found in the LICENSE file.
4
4
 
5
- import { NativeModules, Platform } from "react-native";
6
-
7
- const ReactNativeBlobUtil: ReactNativeBlobUtilNative = NativeModules.ReactNativeBlobUtil;
5
+ import { Platform } from "react-native";
6
+ import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
8
7
 
9
8
  /**
10
9
  * Displays an options menu using UIDocumentInteractionController.presentOptionsMenu
@@ -1,7 +1,5 @@
1
- import {NativeModules} from 'react-native';
2
1
  import type {ReactNativeBlobUtilNative, filedescriptor} from "types";
3
-
4
- const ReactNativeBlobUtil: ReactNativeBlobUtilNative = NativeModules.ReactNativeBlobUtil;
2
+ import ReactNativeBlobUtil from "./codegenSpecs/NativeBlobUtils";
5
3
 
6
4
  function createMediafile(fd: filedescriptor, mediatype: string): Promise {
7
5
  if ((!'parentFolder' in fd)) fd['parentFolder'] = '';
@@ -35,4 +33,4 @@ export default {
35
33
  copyToInternal,
36
34
  getBlob,
37
35
  copyToMediaStore
38
- };
36
+ };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.16.4",
3
+ "version": "0.17.1",
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
  },
@@ -46,5 +46,10 @@
46
46
  "peerDependencies": {
47
47
  "react": "*",
48
48
  "react-native": "*"
49
+ },
50
+ "codegenConfig": {
51
+ "name": "ReactNativeBlobUtilSpec",
52
+ "type": "modules",
53
+ "jsSrcsDir": "codegenSpecs"
49
54
  }
50
55
  }
@@ -1,6 +1,8 @@
1
1
  require "json"
2
2
  package = JSON.parse(File.read('package.json'))
3
3
 
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
4
6
  Pod::Spec.new do |s|
5
7
  s.name = package['name']
6
8
  s.version = package['version']
@@ -10,7 +12,25 @@ Pod::Spec.new do |s|
10
12
  s.homepage = 'n/a'
11
13
  s.source = { :git => "https://github.com/RonRadtke/react-native-blob-util" }
12
14
  s.author = 'RonRadtke'
13
- s.source_files = 'ios/**/*.{h,m}'
15
+ s.source_files = 'ios/**/*.{h,m,mm,swift}'
14
16
  s.platform = :ios, "8.0"
17
+ s.framework = 'AssetsLibrary'
18
+
15
19
  s.dependency 'React-Core'
20
+
21
+ if ENV["RCT_NEW_ARCH_ENABLED"] == "1"
22
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
23
+ s.pod_target_xcconfig = {
24
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
25
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
26
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
27
+ }
28
+
29
+ s.dependency "React-Codegen"
30
+ s.dependency "React-RCTFabric"
31
+ s.dependency "RCT-Folly"
32
+ s.dependency "RCTRequired"
33
+ s.dependency "RCTTypeSafety"
34
+ s.dependency "ReactCommon/turbomodule/core"
35
+ end
16
36
  end
@@ -1,6 +0,0 @@
1
-
2
- [android]
3
- target = Google Inc.:Google APIs:23
4
-
5
- [maven_repositories]
6
- central = https://repo1.maven.org/maven2
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- extends: '@react-native-community',
4
- };
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- bracketSpacing: false,
3
- jsxBracketSameLine: true,
4
- singleQuote: true,
5
- trailingComma: 'all',
6
- };