react-native-blob-util 0.17.2 → 0.18.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 (27) hide show
  1. package/README.md +12 -5
  2. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConst.java +1 -0
  3. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +2 -3
  4. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +29 -12
  5. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilStream.java +8 -3
  6. package/android/src/newarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +11 -0
  7. package/android/src/oldarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +11 -0
  8. package/class/ReactNativeBlobUtilReadStream.js +66 -62
  9. package/class/ReactNativeBlobUtilSession.js +6 -11
  10. package/class/ReactNativeBlobUtilWriteStream.js +4 -9
  11. package/codegenSpecs/NativeBlobUtils.js +6 -9
  12. package/fetch.js +30 -23
  13. package/index.d.ts +4 -0
  14. package/index.js +2 -14
  15. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +5 -4
  16. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +44 -26
  17. package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +117 -36
  18. package/ios/ReactNativeBlobUtilConst.h +1 -0
  19. package/ios/ReactNativeBlobUtilConst.mm +1 -0
  20. package/ios/ReactNativeBlobUtilFS.h +1 -4
  21. package/ios/ReactNativeBlobUtilFS.mm +24 -30
  22. package/ios/ReactNativeBlobUtilNetwork.h +1 -2
  23. package/ios/ReactNativeBlobUtilNetwork.mm +2 -24
  24. package/ios/ReactNativeBlobUtilRequest.h +3 -4
  25. package/ios/ReactNativeBlobUtilRequest.mm +8 -17
  26. package/package.json +4 -4
  27. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj +2 -1
@@ -17,10 +17,8 @@
17
17
 
18
18
  #if __has_include(<React/RCTAssert.h>)
19
19
  #import <React/RCTBridge.h>
20
- #import <React/RCTEventDispatcher.h>
21
20
  #else
22
21
  #import "RCTBridge.h"
23
- #import "RCTEventDispatcher.h"
24
22
  #endif
25
23
 
26
24
 
@@ -58,12 +56,6 @@ NSMutableDictionary *fileStreams = nil;
58
56
  return self;
59
57
  }
60
58
 
61
- - (id)initWithEventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef {
62
- self = [super init];
63
- self.eventDispatcher = eventDispatcherRef;
64
- return self;
65
- }
66
-
67
59
  // static member getter
68
60
  + (NSDictionary *) getFileStreams {
69
61
 
@@ -160,11 +152,10 @@ NSMutableDictionary *fileStreams = nil;
160
152
  bufferSize:(int)bufferSize
161
153
  tick:(int)tick
162
154
  streamId:(NSString *)streamId
163
- eventDispatcherRef:(RCTEventDispatcher *)eventDispatcherRef
155
+ baseModule:(ReactNativeBlobUtil*)baseModule
164
156
  {
165
157
  [[self class] getPathFromUri:uri completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
166
158
 
167
- __block RCTEventDispatcher * event = eventDispatcherRef;
168
159
  __block int read = 0;
169
160
  __block int backoff = tick *1000;
170
161
  __block int chunkSize = bufferSize;
@@ -178,8 +169,8 @@ NSMutableDictionary *fileStreams = nil;
178
169
  if([[NSFileManager defaultManager] fileExistsAtPath:path] == NO)
179
170
  {
180
171
  NSString * message = [NSString stringWithFormat:@"File does not exist at path %@", path];
181
- NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"code": @"ENOENT", @"detail": message };
182
- [event sendDeviceEventWithName:streamId body:payload];
172
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_ERROR, @"code": @"ENOENT", @"detail": message };
173
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
183
174
  free(buffer);
184
175
  return ;
185
176
  }
@@ -187,7 +178,7 @@ NSMutableDictionary *fileStreams = nil;
187
178
  [stream open];
188
179
  while((read = [stream read:buffer maxLength:bufferSize]) > 0)
189
180
  {
190
- [[self class] emitDataChunks:[NSData dataWithBytes:buffer length:read] encoding:encoding streamId:streamId event:event];
181
+ [[self class] emitDataChunks:[NSData dataWithBytes:buffer length:read] encoding:encoding streamId:streamId baseModule:baseModule];
191
182
  if(tick > 0)
192
183
  {
193
184
  usleep(backoff);
@@ -202,7 +193,7 @@ NSMutableDictionary *fileStreams = nil;
202
193
  while((read = [asset getBytes:buffer fromOffset:cursor length:bufferSize error:&err]) > 0)
203
194
  {
204
195
  cursor += read;
205
- [[self class] emitDataChunks:[NSData dataWithBytes:buffer length:read] encoding:encoding streamId:streamId event:event];
196
+ [[self class] emitDataChunks:[NSData dataWithBytes:buffer length:read] encoding:encoding streamId:streamId baseModule:baseModule];
206
197
  if(tick > 0)
207
198
  {
208
199
  usleep(backoff);
@@ -211,8 +202,8 @@ NSMutableDictionary *fileStreams = nil;
211
202
  }
212
203
  else
213
204
  {
214
- NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"code": @"EINVAL", @"detail": @"Unable to resolve URI" };
215
- [event sendDeviceEventWithName:streamId body:payload];
205
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_ERROR, @"code": @"EINVAL", @"detail": @"Unable to resolve URI" };
206
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
216
207
  }
217
208
  // release buffer
218
209
  if(buffer != nil)
@@ -221,13 +212,13 @@ NSMutableDictionary *fileStreams = nil;
221
212
  }
222
213
  @catch (NSError * err)
223
214
  {
224
- NSDictionary * payload = @{ @"event": FS_EVENT_ERROR, @"code": @"EUNSPECIFIED", @"detail": [err description] };
225
- [event sendDeviceEventWithName:streamId body:payload];
215
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_ERROR, @"code": @"EUNSPECIFIED", @"detail": [err description] };
216
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
226
217
  }
227
218
  @finally
228
219
  {
229
- NSDictionary * payload = @{ @"event": FS_EVENT_END, @"detail": @"" };
230
- [event sendDeviceEventWithName:streamId body:payload];
220
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_END, @"detail": @"" };
221
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
231
222
  }
232
223
 
233
224
  }];
@@ -236,7 +227,7 @@ NSMutableDictionary *fileStreams = nil;
236
227
  }
237
228
 
238
229
  // send read stream chunks via native event emitter
239
- + (void) emitDataChunks:(NSData *)data encoding:(NSString *) encoding streamId:(NSString *)streamId event:(RCTEventDispatcher *)event
230
+ + (void) emitDataChunks:(NSData *)data encoding:(NSString *) encoding streamId:(NSString *)streamId baseModule:(ReactNativeBlobUtil *)baseModule
240
231
  {
241
232
  @try
242
233
  {
@@ -244,15 +235,16 @@ NSMutableDictionary *fileStreams = nil;
244
235
  if([[encoding lowercaseString] isEqualToString:@"utf8"])
245
236
  {
246
237
  NSDictionary * payload = @{
238
+ @"streamId":streamId,
247
239
  @"event": FS_EVENT_DATA,
248
240
  @"detail" : [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]
249
241
  };
250
- [event sendDeviceEventWithName:streamId body:payload];
242
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
251
243
  }
252
244
  else if ([[encoding lowercaseString] isEqualToString:@"base64"])
253
245
  {
254
- NSDictionary * payload = @{ @"event": FS_EVENT_DATA, @"detail" : [data base64EncodedStringWithOptions:0] };
255
- [event sendDeviceEventWithName:streamId body:payload];
246
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_DATA, @"detail" : [data base64EncodedStringWithOptions:0] };
247
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
256
248
  }
257
249
  else if([[encoding lowercaseString] isEqualToString:@"ascii"])
258
250
  {
@@ -269,23 +261,25 @@ NSMutableDictionary *fileStreams = nil;
269
261
  }
270
262
  }
271
263
 
272
- NSDictionary * payload = @{ @"event": FS_EVENT_DATA, @"detail" : asciiArray };
273
- [event sendDeviceEventWithName:streamId body:payload];
264
+ NSDictionary * payload = @{ @"streamId":streamId, @"event": FS_EVENT_DATA, @"detail" : asciiArray };
265
+ [baseModule emitEventDict:EVENT_FILESYSTEM body:payload];
274
266
  }
275
267
 
276
268
  }
277
269
  @catch (NSException * ex)
278
270
  {
279
271
  NSString * message = [NSString stringWithFormat:@"Failed to convert data to '%@' encoded string, this might due to the source data is not able to convert using this encoding. source = %@", encoding, [ex description]];
280
- [event
281
- sendDeviceEventWithName:streamId
272
+ [baseModule
273
+ emitEventDict:EVENT_FILESYSTEM
282
274
  body:@{
275
+ @"streamId":streamId,
283
276
  @"event" : MSG_EVENT_ERROR,
284
277
  @"detail" : message
285
278
  }];
286
- [event
287
- sendDeviceEventWithName:MSG_EVENT
279
+ [baseModule
280
+ emitEventDict:MSG_EVENT
288
281
  body:@{
282
+ @"streamId":streamId,
289
283
  @"event" : MSG_EVENT_WARN,
290
284
  @"detail" : message
291
285
  }];
@@ -30,12 +30,11 @@
30
30
 
31
31
  + (ReactNativeBlobUtilNetwork* _Nullable)sharedInstance;
32
32
  + (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
33
- + (void) emitExpiredTasks:(RCTEventDispatcher *) eventDispatcher;
34
33
 
35
34
  - (nullable id) init;
36
35
  - (void) sendRequest:(NSDictionary * _Nullable )options
37
36
  contentLength:(long)contentLength
38
- eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
37
+ baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
39
38
  taskId:(NSString * _Nullable)taskId
40
39
  withRequest:(NSURLRequest * _Nullable)req
41
40
  callback:(_Nullable RCTResponseSenderBlock) callback;
@@ -16,12 +16,10 @@
16
16
  #if __has_include(<React/RCTAssert.h>)
17
17
  #import <React/RCTRootView.h>
18
18
  #import <React/RCTLog.h>
19
- #import <React/RCTEventDispatcher.h>
20
19
  #import <React/RCTBridge.h>
21
20
  #else
22
21
  #import "RCTRootView.h"
23
22
  #import "RCTLog.h"
24
- #import "RCTEventDispatcher.h"
25
23
  #import "RCTBridge.h"
26
24
  #endif
27
25
 
@@ -72,7 +70,7 @@ static void initialize_tables() {
72
70
 
73
71
  - (void) sendRequest:(__weak NSDictionary * _Nullable )options
74
72
  contentLength:(long) contentLength
75
- eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
73
+ baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
76
74
  taskId:(NSString * _Nullable)taskId
77
75
  withRequest:(__weak NSURLRequest * _Nullable)req
78
76
  callback:(_Nullable RCTResponseSenderBlock) callback
@@ -80,7 +78,7 @@ static void initialize_tables() {
80
78
  ReactNativeBlobUtilRequest *request = [[ReactNativeBlobUtilRequest alloc] init];
81
79
  [request sendRequest:options
82
80
  contentLength:contentLength
83
- eventDispatcher:eventDispatcherRef
81
+ baseModule:baseModule
84
82
  taskId:taskId
85
83
  withRequest:req
86
84
  taskOperationQueue:self.taskQueue
@@ -158,24 +156,4 @@ static void initialize_tables() {
158
156
  return mheaders;
159
157
  }
160
158
 
161
- // #115 Invoke fetch.expire event on those expired requests so that the expired event can be handled
162
- + (void) emitExpiredTasks:(RCTEventDispatcher *)eventDispatcher
163
- {
164
- @synchronized ([ReactNativeBlobUtilNetwork class]){
165
- NSEnumerator * emu = [expirationTable keyEnumerator];
166
- NSString * key;
167
-
168
- while ((key = [emu nextObject]))
169
- {
170
- id args = @{ @"taskId": key };
171
- [eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
172
-
173
- }
174
-
175
- // clear expired task entries
176
- [expirationTable removeAllObjects];
177
- expirationTable = [[NSMapTable alloc] init];
178
- }
179
- }
180
-
181
159
  @end
@@ -12,13 +12,12 @@
12
12
  #import <Foundation/Foundation.h>
13
13
 
14
14
  #import "ReactNativeBlobUtilProgress.h"
15
+ #import "ReactNativeBlobUtil.h"
15
16
 
16
17
  #if __has_include(<React/RCTAssert.h>)
17
18
  #import <React/RCTBridgeModule.h>
18
- #import <React/RCTEventDispatcher.h>
19
19
  #else
20
20
  #import "RCTBridgeModule.h"
21
- #import "RCTEventDispatcher.h"
22
21
  #endif
23
22
 
24
23
  @interface ReactNativeBlobUtilRequest : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>
@@ -29,7 +28,7 @@
29
28
  @property (nonatomic) BOOL isServerPush;
30
29
  @property (nullable, nonatomic) NSMutableData * respData;
31
30
  @property (nullable, strong, nonatomic) RCTResponseSenderBlock callback;
32
- @property (nullable, nonatomic) RCTEventDispatcher * eventDispatcher;
31
+ @property (nullable, strong, nonatomic) ReactNativeBlobUtil * baseModule;
33
32
  @property (nullable, nonatomic) NSDictionary * options;
34
33
  @property (nullable, nonatomic) NSError * error;
35
34
  @property (nullable, nonatomic) ReactNativeBlobUtilProgress *progressConfig;
@@ -38,7 +37,7 @@
38
37
 
39
38
  - (void) sendRequest:(NSDictionary * _Nullable )options
40
39
  contentLength:(long)contentLength
41
- eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
40
+ baseModule:(ReactNativeBlobUtil * _Nullable)baseModule
42
41
  taskId:(NSString * _Nullable)taskId
43
42
  withRequest:(NSURLRequest * _Nullable)req
44
43
  taskOperationQueue:(NSOperationQueue * _Nonnull)operationQueue
@@ -15,12 +15,6 @@
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
-
24
18
 
25
19
  typedef NS_ENUM(NSUInteger, ResponseFormat) {
26
20
  UTF8,
@@ -53,7 +47,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
53
47
  @synthesize receivedBytes;
54
48
  @synthesize respData;
55
49
  @synthesize callback;
56
- @synthesize eventDispatcher;
50
+ @synthesize baseModule;
57
51
  @synthesize options;
58
52
  @synthesize error;
59
53
 
@@ -73,7 +67,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
73
67
  // send HTTP request
74
68
  - (void) sendRequest:(__weak NSDictionary * _Nullable )options
75
69
  contentLength:(long) contentLength
76
- eventDispatcher:(RCTEventDispatcher * _Nullable)eventDispatcherRef
70
+ baseModule:(__strong ReactNativeBlobUtil * _Nullable)baseModule
77
71
  taskId:(NSString * _Nullable)taskId
78
72
  withRequest:(__weak NSURLRequest * _Nullable)req
79
73
  taskOperationQueue:(NSOperationQueue * _Nonnull)operationQueue
@@ -82,7 +76,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
82
76
  self.taskId = taskId;
83
77
  self.respData = [[NSMutableData alloc] initWithLength:0];
84
78
  self.callback = callback;
85
- self.eventDispatcher = eventDispatcherRef;
79
+ self.baseModule = baseModule;
86
80
  self.expectedBytes = 0;
87
81
  self.receivedBytes = 0;
88
82
  self.options = options;
@@ -213,8 +207,8 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
213
207
 
214
208
  if (self.isServerPush) {
215
209
  if (partBuffer) {
216
- [self.eventDispatcher
217
- sendDeviceEventWithName:EVENT_SERVER_PUSH
210
+ [self.baseModule
211
+ emitEventDict:EVENT_SERVER_PUSH
218
212
  body:@{
219
213
  @"taskId": taskId,
220
214
  @"chunk": [partBuffer base64EncodedStringWithOptions:0],
@@ -269,8 +263,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
269
263
  [cookieStore setCookies:cookies forURL:response.URL mainDocumentURL:nil];
270
264
  }
271
265
  }
272
- [self.eventDispatcher
273
- sendDeviceEventWithName: EVENT_STATE_CHANGE
266
+ [self.baseModule emitEventDict : EVENT_STATE_CHANGE
274
267
  body:@{
275
268
  @"taskId": taskId,
276
269
  @"state": @"2",
@@ -359,8 +352,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
359
352
  NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
360
353
 
361
354
  if ([self.progressConfig shouldReport:now]) {
362
- [self.eventDispatcher
363
- sendDeviceEventWithName:EVENT_PROGRESS
355
+ [self.baseModule emitEventDict :EVENT_PROGRESS
364
356
  body:@{
365
357
  @"taskId": taskId,
366
358
  @"written": [NSString stringWithFormat:@"%lld", (long long) receivedBytes],
@@ -473,8 +465,7 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
473
465
  NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
474
466
 
475
467
  if ([self.uploadProgressConfig shouldReport:now]) {
476
- [self.eventDispatcher
477
- sendDeviceEventWithName:EVENT_PROGRESS_UPLOAD
468
+ [self.baseModule emitEventDict:EVENT_PROGRESS_UPLOAD
478
469
  body:@{
479
470
  @"taskId": taskId,
480
471
  @"written": [NSString stringWithFormat:@"%ld", (long) totalBytesWritten],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.17.2",
3
+ "version": "0.18.1",
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",
6
6
  "scripts": {
@@ -35,13 +35,13 @@
35
35
  "wkh237 <xeiyan@gmail.com>"
36
36
  ],
37
37
  "devDependencies": {
38
- "react": "16.13.1",
39
- "react-native": "^0.68.2",
38
+ "react": "18.0.0",
39
+ "react-native": "0.69.7",
40
40
  "@typescript-eslint/parser": "^3.4.0",
41
41
  "@react-native-community/eslint-config": "^3.0.0",
42
42
  "eslint-config-defaults": "^9.0.0",
43
43
  "eslint-plugin-react": "^7.24.0",
44
- "eslint": "^6.8.0"
44
+ "eslint": ">7.0.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "*",
@@ -60,6 +60,7 @@
60
60
  <PlatformToolset>v140</PlatformToolset>
61
61
  <PlatformToolset Condition="'$(VisualStudioVersion)' == '15.0'">v141</PlatformToolset>
62
62
  <PlatformToolset Condition="'$(VisualStudioVersion)' == '16.0'">v142</PlatformToolset>
63
+ <PlatformToolset Condition="'$(VisualStudioVersion)' == '17.0'">v142</PlatformToolset>
63
64
  <CharacterSet>Unicode</CharacterSet>
64
65
  <GenerateManifest>false</GenerateManifest>
65
66
  </PropertyGroup>
@@ -177,4 +178,4 @@
177
178
  <LinkLibraryDependencies>true</LinkLibraryDependencies>
178
179
  </ProjectReference>
179
180
  </ItemGroup>
180
- </Project>
181
+ </Project>