react-native-blob-util 0.18.5 → 0.19.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.
@@ -95,8 +95,12 @@ public class ReactNativeBlobUtilMediaCollection {
95
95
 
96
96
  Uri mediauri = getMediaUri(mt);
97
97
 
98
- // Keeps a handle to the new file's URI in case we need to modify it later.
99
- return resolver.insert(mediauri, fileDetails);
98
+ try {
99
+ // Keeps a handle to the new file's URI in case we need to modify it later.
100
+ return resolver.insert(mediauri, fileDetails);
101
+ } catch (Exception e) {
102
+ return null;
103
+ }
100
104
  } else {
101
105
  File f = new File(relativePath + file.getFullPath());
102
106
  if (true) {
package/fetch.js CHANGED
@@ -13,7 +13,6 @@ const eventEmitter = new NativeEventEmitter(ReactNativeBlobUtil);
13
13
  eventEmitter.addListener('ReactNativeBlobUtilMessage', (e) => {
14
14
  if (typeof e === 'string') e = JSON.parse(e);
15
15
 
16
- console.log('add listener')
17
16
  if (e.event === 'warn') {
18
17
  console.warn(e.detail);
19
18
  }
@@ -17,13 +17,6 @@ typedef NS_ENUM(NSUInteger, ProgressType) {
17
17
  };
18
18
 
19
19
  @interface ReactNativeBlobUtilProgress : NSObject
20
- {
21
- NSNumber * count;
22
- NSNumber * interval;
23
- ProgressType type;
24
- BOOL enable;
25
-
26
- }
27
20
 
28
21
  @property (nonatomic) NSNumber * count;
29
22
  @property (nonatomic) NSNumber * interval;
@@ -349,17 +349,35 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
349
349
  return;
350
350
  }
351
351
 
352
- NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
352
+ // For non-chunked download, progress is received / expected
353
+ // For chunked download, progress can be either 0 (started) or 1 (ended)
354
+ NSNumber *now;
355
+ if (expectedBytes != NSURLResponseUnknownLength) {
356
+ now = [NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
357
+ } else {
358
+ now = @0;
359
+ }
353
360
 
354
361
  if ([self.progressConfig shouldReport:now]) {
355
- [self.baseModule emitEventDict :EVENT_PROGRESS
356
- body:@{
362
+ NSDictionary *body;
363
+ if (expectedBytes == NSURLResponseUnknownLength) {
364
+ // For chunked downloads
365
+ body = @{
366
+ @"taskId": taskId,
367
+ @"written": [NSString stringWithFormat:@"%d", 0],
368
+ @"total": [NSString stringWithFormat:@"%lld", (long long) expectedBytes],
369
+ @"chunk": chunkString,
370
+ };
371
+ } else {
372
+ // For non-chunked downloads
373
+ body = @{
357
374
  @"taskId": taskId,
358
375
  @"written": [NSString stringWithFormat:@"%lld", (long long) receivedBytes],
359
376
  @"total": [NSString stringWithFormat:@"%lld", (long long) expectedBytes],
360
- @"chunk": chunkString
361
- }
362
- ];
377
+ @"chunk": chunkString,
378
+ };
379
+ }
380
+ [self.baseModule emitEventDict:EVENT_PROGRESS body:body];
363
381
  }
364
382
  }
365
383
 
@@ -392,6 +410,14 @@ typedef NS_ENUM(NSUInteger, ResponseFormat) {
392
410
  } else {
393
411
  errMsg = [error localizedDescription];
394
412
  }
413
+ } else if ([self.progressConfig shouldReport:@1] && expectedBytes == NSURLResponseUnknownLength) {
414
+ // For chunked downloads
415
+ [self.baseModule emitEventDict:EVENT_PROGRESS body:@{
416
+ @"taskId": taskId,
417
+ @"written": [NSString stringWithFormat:@"%lld", (long long) receivedBytes],
418
+ @"total": [NSString stringWithFormat:@"%lld", (long long) receivedBytes],
419
+ @"chunk": @"",
420
+ }];
395
421
  }
396
422
 
397
423
  if (respFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-blob-util",
3
- "version": "0.18.5",
3
+ "version": "0.19.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",
6
6
  "scripts": {
@@ -17,7 +17,29 @@ Pod::Spec.new do |s|
17
17
  s.framework = 'AssetsLibrary'
18
18
 
19
19
  if fabric_enabled
20
- install_modules_dependencies(s)
20
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
+ if respond_to?(:install_modules_dependencies, true)
23
+ install_modules_dependencies(s)
24
+ else
25
+ # just for backward compatibility: if React Native version <= 0.70.x
26
+ s.compiler_flags = "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32 -DRCT_NEW_ARCH_ENABLED=1"
27
+ s.pod_target_xcconfig = {
28
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
29
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
30
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
31
+ }
32
+
33
+ s.dependency 'React-Core'
34
+ s.dependency "React-Codegen"
35
+ s.dependency "React-RCTFabric"
36
+ s.dependency "RCT-Folly"
37
+ s.dependency "RCTRequired"
38
+ s.dependency "RCTTypeSafety"
39
+ s.dependency "ReactCommon/turbomodule/core"
40
+ end
41
+ else
42
+ s.dependency 'React-Core'
21
43
  end
22
44
 
23
45
  end