react-native-blob-util 0.19.1 → 0.19.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.
Files changed (91) hide show
  1. package/.eslintrc.js +56 -56
  2. package/LICENSE +21 -21
  3. package/Migration.md +41 -41
  4. package/README.md +1071 -1071
  5. package/android/gradle.properties +1 -1
  6. package/android/proguard-rules.pro +17 -17
  7. package/android/src/main/AndroidManifest.xml +39 -40
  8. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +57 -57
  9. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConst.java +20 -20
  10. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +2 -2
  11. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFileTransformer.java +9 -9
  12. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.java +431 -431
  13. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilProgressConfig.java +39 -39
  14. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +972 -968
  15. package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilDefaultResp.java +98 -98
  16. package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +157 -157
  17. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -19
  18. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileProvider.java +4 -4
  19. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -70
  20. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/PathResolver.java +223 -223
  21. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/Tls12SocketFactory.java +68 -68
  22. package/android/src/main/res/values/strings.xml +3 -3
  23. package/android/src/main/res/xml/provider_paths.xml +12 -12
  24. package/android/src/newarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +1 -1
  25. package/android.js +58 -58
  26. package/class/ReactNativeBlobUtilCanceledFetchError.js +9 -9
  27. package/class/ReactNativeBlobUtilFile.js +5 -5
  28. package/class/ReactNativeBlobUtilReadStream.js +84 -84
  29. package/class/ReactNativeBlobUtilSession.js +68 -68
  30. package/class/ReactNativeBlobUtilWriteStream.js +50 -50
  31. package/class/StatefulPromise.js +7 -7
  32. package/codegenSpecs/NativeBlobUtils.js +86 -82
  33. package/components/Fetch.onPress.js +10 -10
  34. package/components/Fetch.when.js +15 -15
  35. package/fetch.js +344 -344
  36. package/fs.js +480 -480
  37. package/index.d.ts +871 -871
  38. package/index.js +64 -64
  39. package/index.js.flow +191 -191
  40. package/index.web.js +1 -1
  41. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +55 -55
  42. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +993 -993
  43. package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +403 -403
  44. package/ios/ReactNativeBlobUtilConst.h +58 -58
  45. package/ios/ReactNativeBlobUtilConst.mm +47 -47
  46. package/ios/ReactNativeBlobUtilFS.h +108 -108
  47. package/ios/ReactNativeBlobUtilFS.mm +977 -977
  48. package/ios/ReactNativeBlobUtilFileTransformer.h +23 -23
  49. package/ios/ReactNativeBlobUtilFileTransformer.mm +20 -20
  50. package/ios/ReactNativeBlobUtilNetwork.h +49 -49
  51. package/ios/ReactNativeBlobUtilNetwork.mm +159 -159
  52. package/ios/ReactNativeBlobUtilProgress.h +32 -32
  53. package/ios/ReactNativeBlobUtilProgress.mm +57 -57
  54. package/ios/ReactNativeBlobUtilReqBuilder.h +37 -37
  55. package/ios/ReactNativeBlobUtilReqBuilder.mm +292 -292
  56. package/ios/ReactNativeBlobUtilRequest.h +48 -48
  57. package/ios/ReactNativeBlobUtilRequest.mm +535 -535
  58. package/ios.js +61 -61
  59. package/json-stream.js +42 -42
  60. package/lib/oboe-browser.js +2703 -2703
  61. package/mediacollection.js +36 -36
  62. package/package.json +55 -55
  63. package/polyfill/Blob.js +362 -362
  64. package/polyfill/Event.js +11 -11
  65. package/polyfill/EventTarget.js +78 -78
  66. package/polyfill/Fetch.js +219 -219
  67. package/polyfill/File.js +27 -27
  68. package/polyfill/FileReader.js +91 -91
  69. package/polyfill/ProgressEvent.js +32 -32
  70. package/polyfill/XMLHttpRequest.js +466 -466
  71. package/polyfill/XMLHttpRequestEventTarget.js +126 -126
  72. package/polyfill/index.js +11 -11
  73. package/react-native-blob-util.podspec +45 -45
  74. package/types.js +69 -69
  75. package/utils/log.js +40 -40
  76. package/utils/unicode.js +7 -7
  77. package/utils/uri.js +33 -33
  78. package/utils/uuid.js +4 -4
  79. package/windows/README.md +2 -2
  80. package/windows/ReactNativeBlobUtil/PropertySheet.props +15 -15
  81. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.cpp +1701 -1693
  82. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.def +3 -3
  83. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.h +379 -366
  84. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj +181 -181
  85. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj.filters +31 -31
  86. package/windows/ReactNativeBlobUtil/ReactPackageProvider.cpp +15 -15
  87. package/windows/ReactNativeBlobUtil/ReactPackageProvider.h +20 -20
  88. package/windows/ReactNativeBlobUtil/ReactPackageProvider.idl +9 -9
  89. package/windows/ReactNativeBlobUtil/packages.config +3 -3
  90. package/windows/ReactNativeBlobUtil/pch.cpp +1 -1
  91. package/windows/ReactNativeBlobUtil/pch.h +3 -3
@@ -1,98 +1,98 @@
1
- package com.ReactNativeBlobUtil.Response;
2
-
3
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilConst;
4
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilProgressConfig;
5
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilReq;
6
- import com.facebook.react.bridge.Arguments;
7
- import com.facebook.react.bridge.ReactApplicationContext;
8
- import com.facebook.react.bridge.WritableMap;
9
- import com.facebook.react.modules.core.DeviceEventManagerModule;
10
-
11
- import java.io.IOException;
12
- import java.nio.charset.Charset;
13
-
14
- import okhttp3.MediaType;
15
- import okhttp3.ResponseBody;
16
- import okio.Buffer;
17
- import okio.BufferedSource;
18
- import okio.Okio;
19
- import okio.Source;
20
- import okio.Timeout;
21
-
22
- /**
23
- * Created by wkh237 on 2016/7/11.
24
- */
25
- public class ReactNativeBlobUtilDefaultResp extends ResponseBody {
26
-
27
- String mTaskId;
28
- ReactApplicationContext rctContext;
29
- ResponseBody originalBody;
30
- boolean isIncrement = false;
31
-
32
- public ReactNativeBlobUtilDefaultResp(ReactApplicationContext ctx, String taskId, ResponseBody body, boolean isIncrement) {
33
- this.rctContext = ctx;
34
- this.mTaskId = taskId;
35
- this.originalBody = body;
36
- this.isIncrement = isIncrement;
37
- }
38
-
39
- @Override
40
- public MediaType contentType() {
41
- return originalBody.contentType();
42
- }
43
-
44
- @Override
45
- public long contentLength() {
46
- return originalBody.contentLength();
47
- }
48
-
49
- @Override
50
- public BufferedSource source() {
51
- return Okio.buffer(new ProgressReportingSource(originalBody.source()));
52
- }
53
-
54
- private class ProgressReportingSource implements Source {
55
-
56
- BufferedSource mOriginalSource;
57
- long bytesRead = 0;
58
-
59
- ProgressReportingSource(BufferedSource originalSource) {
60
- mOriginalSource = originalSource;
61
- }
62
-
63
- @Override
64
- public long read(Buffer sink, long byteCount) throws IOException {
65
-
66
- long read = mOriginalSource.read(sink, byteCount);
67
- bytesRead += read > 0 ? read : 0;
68
- ReactNativeBlobUtilProgressConfig reportConfig = ReactNativeBlobUtilReq.getReportProgress(mTaskId);
69
- long cLen = contentLength();
70
- if (reportConfig != null && cLen != 0 && reportConfig.shouldReport(bytesRead / contentLength())) {
71
- WritableMap args = Arguments.createMap();
72
- args.putString("taskId", mTaskId);
73
- args.putString("written", String.valueOf(bytesRead));
74
- args.putString("total", String.valueOf(contentLength()));
75
- if (isIncrement) {
76
- args.putString("chunk", sink.readString(Charset.defaultCharset()));
77
- } else {
78
- args.putString("chunk", "");
79
- }
80
-
81
- rctContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
82
- .emit(ReactNativeBlobUtilConst.EVENT_PROGRESS, args);
83
- }
84
- return read;
85
- }
86
-
87
- @Override
88
- public Timeout timeout() {
89
- return null;
90
- }
91
-
92
- @Override
93
- public void close() throws IOException {
94
-
95
- }
96
- }
97
-
98
- }
1
+ package com.ReactNativeBlobUtil.Response;
2
+
3
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilConst;
4
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilProgressConfig;
5
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilReq;
6
+ import com.facebook.react.bridge.Arguments;
7
+ import com.facebook.react.bridge.ReactApplicationContext;
8
+ import com.facebook.react.bridge.WritableMap;
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
10
+
11
+ import java.io.IOException;
12
+ import java.nio.charset.Charset;
13
+
14
+ import okhttp3.MediaType;
15
+ import okhttp3.ResponseBody;
16
+ import okio.Buffer;
17
+ import okio.BufferedSource;
18
+ import okio.Okio;
19
+ import okio.Source;
20
+ import okio.Timeout;
21
+
22
+ /**
23
+ * Created by wkh237 on 2016/7/11.
24
+ */
25
+ public class ReactNativeBlobUtilDefaultResp extends ResponseBody {
26
+
27
+ String mTaskId;
28
+ ReactApplicationContext rctContext;
29
+ ResponseBody originalBody;
30
+ boolean isIncrement = false;
31
+
32
+ public ReactNativeBlobUtilDefaultResp(ReactApplicationContext ctx, String taskId, ResponseBody body, boolean isIncrement) {
33
+ this.rctContext = ctx;
34
+ this.mTaskId = taskId;
35
+ this.originalBody = body;
36
+ this.isIncrement = isIncrement;
37
+ }
38
+
39
+ @Override
40
+ public MediaType contentType() {
41
+ return originalBody.contentType();
42
+ }
43
+
44
+ @Override
45
+ public long contentLength() {
46
+ return originalBody.contentLength();
47
+ }
48
+
49
+ @Override
50
+ public BufferedSource source() {
51
+ return Okio.buffer(new ProgressReportingSource(originalBody.source()));
52
+ }
53
+
54
+ private class ProgressReportingSource implements Source {
55
+
56
+ BufferedSource mOriginalSource;
57
+ long bytesRead = 0;
58
+
59
+ ProgressReportingSource(BufferedSource originalSource) {
60
+ mOriginalSource = originalSource;
61
+ }
62
+
63
+ @Override
64
+ public long read(Buffer sink, long byteCount) throws IOException {
65
+
66
+ long read = mOriginalSource.read(sink, byteCount);
67
+ bytesRead += read > 0 ? read : 0;
68
+ ReactNativeBlobUtilProgressConfig reportConfig = ReactNativeBlobUtilReq.getReportProgress(mTaskId);
69
+ long cLen = contentLength();
70
+ if (reportConfig != null && cLen != 0 && reportConfig.shouldReport(bytesRead / contentLength())) {
71
+ WritableMap args = Arguments.createMap();
72
+ args.putString("taskId", mTaskId);
73
+ args.putString("written", String.valueOf(bytesRead));
74
+ args.putString("total", String.valueOf(contentLength()));
75
+ if (isIncrement) {
76
+ args.putString("chunk", sink.readString(Charset.defaultCharset()));
77
+ } else {
78
+ args.putString("chunk", "");
79
+ }
80
+
81
+ rctContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
82
+ .emit(ReactNativeBlobUtilConst.EVENT_PROGRESS, args);
83
+ }
84
+ return read;
85
+ }
86
+
87
+ @Override
88
+ public Timeout timeout() {
89
+ return null;
90
+ }
91
+
92
+ @Override
93
+ public void close() throws IOException {
94
+
95
+ }
96
+ }
97
+
98
+ }
@@ -1,157 +1,157 @@
1
- package com.ReactNativeBlobUtil.Response;
2
-
3
- import androidx.annotation.NonNull;
4
-
5
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilConst;
6
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilProgressConfig;
7
- import com.ReactNativeBlobUtil.ReactNativeBlobUtilReq;
8
- import com.facebook.react.bridge.Arguments;
9
- import com.facebook.react.bridge.ReactApplicationContext;
10
- import com.facebook.react.bridge.WritableMap;
11
- import com.facebook.react.modules.core.DeviceEventManagerModule;
12
-
13
- import java.io.File;
14
- import java.io.FileOutputStream;
15
- import java.io.IOException;
16
-
17
- import okhttp3.MediaType;
18
- import okhttp3.ResponseBody;
19
- import okio.Buffer;
20
- import okio.BufferedSource;
21
- import okio.Okio;
22
- import okio.Source;
23
- import okio.Timeout;
24
-
25
- /**
26
- * Created by wkh237 on 2016/7/11.
27
- */
28
- public class ReactNativeBlobUtilFileResp extends ResponseBody {
29
-
30
- String mTaskId;
31
- ResponseBody originalBody;
32
- String mPath;
33
- long bytesDownloaded = 0;
34
- ReactApplicationContext rctContext;
35
- FileOutputStream ofStream;
36
- boolean isEndMarkerReceived;
37
-
38
- public ReactNativeBlobUtilFileResp(ResponseBody body) {
39
- super();
40
- this.originalBody = body;
41
- }
42
-
43
- public ReactNativeBlobUtilFileResp(ReactApplicationContext ctx, String taskId, ResponseBody body, String path, boolean overwrite) throws IOException {
44
- super();
45
- this.rctContext = ctx;
46
- this.mTaskId = taskId;
47
- this.originalBody = body;
48
- assert path != null;
49
- this.mPath = path;
50
- this.isEndMarkerReceived = false;
51
- if (path != null) {
52
- boolean appendToExistingFile = !overwrite;
53
- path = path.replace("?append=true", "");
54
- mPath = path;
55
- File f = new File(path);
56
-
57
- File parent = f.getParentFile();
58
- if (parent != null && !parent.exists() && !parent.mkdirs()) {
59
- throw new IllegalStateException("Couldn't create dir: " + parent);
60
- }
61
-
62
- if (!f.exists())
63
- f.createNewFile();
64
- ofStream = new FileOutputStream(new File(path), appendToExistingFile);
65
- }
66
- }
67
-
68
- @Override
69
- public MediaType contentType() {
70
- return originalBody.contentType();
71
- }
72
-
73
- @Override
74
- public long contentLength() {
75
- if (originalBody.contentLength() > Integer.MAX_VALUE) {
76
- // This is a workaround for a bug Okio buffer where it can't handle larger than int.
77
- return Integer.MAX_VALUE;
78
- }
79
- return originalBody.contentLength();
80
- }
81
-
82
- public boolean isDownloadComplete() {
83
- return (bytesDownloaded == contentLength()) // Case of non-chunked downloads
84
- || (contentLength() == -1 && isEndMarkerReceived); // Case of chunked downloads
85
- }
86
-
87
- @Override
88
- public BufferedSource source() {
89
- ProgressReportingSource countable = new ProgressReportingSource();
90
- return Okio.buffer(countable);
91
- }
92
-
93
- private class ProgressReportingSource implements Source {
94
- @Override
95
- public long read(@NonNull Buffer sink, long byteCount) throws IOException {
96
- try {
97
- byte[] bytes = new byte[(int) byteCount];
98
- long read = originalBody.byteStream().read(bytes, 0, (int) byteCount);
99
- bytesDownloaded += read > 0 ? read : 0;
100
- if (read > 0) {
101
- ofStream.write(bytes, 0, (int) read);
102
- } else if (contentLength() == -1 && read == -1) {
103
- // End marker has been received for chunked download
104
- isEndMarkerReceived = true;
105
- }
106
- ReactNativeBlobUtilProgressConfig reportConfig = ReactNativeBlobUtilReq.getReportProgress(mTaskId);
107
-
108
- if (contentLength() != 0) {
109
-
110
- // For non-chunked download, progress is received / total
111
- // For chunked download, progress can be either 0 (started) or 1 (ended)
112
- float progress = (contentLength() != -1) ? bytesDownloaded / contentLength() : ((isEndMarkerReceived) ? 1 : 0);
113
-
114
- if (reportConfig != null && reportConfig.shouldReport(progress /* progress */)) {
115
- if (contentLength() != -1) {
116
- // For non-chunked downloads
117
- reportProgress(mTaskId, bytesDownloaded, contentLength());
118
- } else {
119
- // For chunked downloads
120
- if (!isEndMarkerReceived) {
121
- reportProgress(mTaskId, 0, contentLength());
122
- } else {
123
- reportProgress(mTaskId, bytesDownloaded, bytesDownloaded);
124
- }
125
- }
126
- }
127
-
128
- }
129
-
130
- return read;
131
- } catch (Exception ex) {
132
- return -1;
133
- }
134
- }
135
-
136
- private void reportProgress(String taskId, long bytesDownloaded, long contentLength) {
137
- WritableMap args = Arguments.createMap();
138
- args.putString("taskId", taskId);
139
- args.putString("written", String.valueOf(bytesDownloaded));
140
- args.putString("total", String.valueOf(contentLength));
141
- rctContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
142
- .emit(ReactNativeBlobUtilConst.EVENT_PROGRESS, args);
143
- }
144
-
145
- @Override
146
- public Timeout timeout() {
147
- return null;
148
- }
149
-
150
- @Override
151
- public void close() throws IOException {
152
- ofStream.close();
153
-
154
- }
155
- }
156
-
157
- }
1
+ package com.ReactNativeBlobUtil.Response;
2
+
3
+ import androidx.annotation.NonNull;
4
+
5
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilConst;
6
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilProgressConfig;
7
+ import com.ReactNativeBlobUtil.ReactNativeBlobUtilReq;
8
+ import com.facebook.react.bridge.Arguments;
9
+ import com.facebook.react.bridge.ReactApplicationContext;
10
+ import com.facebook.react.bridge.WritableMap;
11
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
12
+
13
+ import java.io.File;
14
+ import java.io.FileOutputStream;
15
+ import java.io.IOException;
16
+
17
+ import okhttp3.MediaType;
18
+ import okhttp3.ResponseBody;
19
+ import okio.Buffer;
20
+ import okio.BufferedSource;
21
+ import okio.Okio;
22
+ import okio.Source;
23
+ import okio.Timeout;
24
+
25
+ /**
26
+ * Created by wkh237 on 2016/7/11.
27
+ */
28
+ public class ReactNativeBlobUtilFileResp extends ResponseBody {
29
+
30
+ String mTaskId;
31
+ ResponseBody originalBody;
32
+ String mPath;
33
+ long bytesDownloaded = 0;
34
+ ReactApplicationContext rctContext;
35
+ FileOutputStream ofStream;
36
+ boolean isEndMarkerReceived;
37
+
38
+ public ReactNativeBlobUtilFileResp(ResponseBody body) {
39
+ super();
40
+ this.originalBody = body;
41
+ }
42
+
43
+ public ReactNativeBlobUtilFileResp(ReactApplicationContext ctx, String taskId, ResponseBody body, String path, boolean overwrite) throws IOException {
44
+ super();
45
+ this.rctContext = ctx;
46
+ this.mTaskId = taskId;
47
+ this.originalBody = body;
48
+ assert path != null;
49
+ this.mPath = path;
50
+ this.isEndMarkerReceived = false;
51
+ if (path != null) {
52
+ boolean appendToExistingFile = !overwrite;
53
+ path = path.replace("?append=true", "");
54
+ mPath = path;
55
+ File f = new File(path);
56
+
57
+ File parent = f.getParentFile();
58
+ if (parent != null && !parent.exists() && !parent.mkdirs()) {
59
+ throw new IllegalStateException("Couldn't create dir: " + parent);
60
+ }
61
+
62
+ if (!f.exists())
63
+ f.createNewFile();
64
+ ofStream = new FileOutputStream(new File(path), appendToExistingFile);
65
+ }
66
+ }
67
+
68
+ @Override
69
+ public MediaType contentType() {
70
+ return originalBody.contentType();
71
+ }
72
+
73
+ @Override
74
+ public long contentLength() {
75
+ if (originalBody.contentLength() > Integer.MAX_VALUE) {
76
+ // This is a workaround for a bug Okio buffer where it can't handle larger than int.
77
+ return Integer.MAX_VALUE;
78
+ }
79
+ return originalBody.contentLength();
80
+ }
81
+
82
+ public boolean isDownloadComplete() {
83
+ return (bytesDownloaded == contentLength()) // Case of non-chunked downloads
84
+ || (contentLength() == -1 && isEndMarkerReceived); // Case of chunked downloads
85
+ }
86
+
87
+ @Override
88
+ public BufferedSource source() {
89
+ ProgressReportingSource countable = new ProgressReportingSource();
90
+ return Okio.buffer(countable);
91
+ }
92
+
93
+ private class ProgressReportingSource implements Source {
94
+ @Override
95
+ public long read(@NonNull Buffer sink, long byteCount) throws IOException {
96
+ try {
97
+ byte[] bytes = new byte[(int) byteCount];
98
+ long read = originalBody.byteStream().read(bytes, 0, (int) byteCount);
99
+ bytesDownloaded += read > 0 ? read : 0;
100
+ if (read > 0) {
101
+ ofStream.write(bytes, 0, (int) read);
102
+ } else if (contentLength() == -1 && read == -1) {
103
+ // End marker has been received for chunked download
104
+ isEndMarkerReceived = true;
105
+ }
106
+ ReactNativeBlobUtilProgressConfig reportConfig = ReactNativeBlobUtilReq.getReportProgress(mTaskId);
107
+
108
+ if (contentLength() != 0) {
109
+
110
+ // For non-chunked download, progress is received / total
111
+ // For chunked download, progress can be either 0 (started) or 1 (ended)
112
+ float progress = (contentLength() != -1) ? bytesDownloaded / contentLength() : ((isEndMarkerReceived) ? 1 : 0);
113
+
114
+ if (reportConfig != null && reportConfig.shouldReport(progress /* progress */)) {
115
+ if (contentLength() != -1) {
116
+ // For non-chunked downloads
117
+ reportProgress(mTaskId, bytesDownloaded, contentLength());
118
+ } else {
119
+ // For chunked downloads
120
+ if (!isEndMarkerReceived) {
121
+ reportProgress(mTaskId, 0, contentLength());
122
+ } else {
123
+ reportProgress(mTaskId, bytesDownloaded, bytesDownloaded);
124
+ }
125
+ }
126
+ }
127
+
128
+ }
129
+
130
+ return read;
131
+ } catch (Exception ex) {
132
+ return -1;
133
+ }
134
+ }
135
+
136
+ private void reportProgress(String taskId, long bytesDownloaded, long contentLength) {
137
+ WritableMap args = Arguments.createMap();
138
+ args.putString("taskId", taskId);
139
+ args.putString("written", String.valueOf(bytesDownloaded));
140
+ args.putString("total", String.valueOf(contentLength));
141
+ rctContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
142
+ .emit(ReactNativeBlobUtilConst.EVENT_PROGRESS, args);
143
+ }
144
+
145
+ @Override
146
+ public Timeout timeout() {
147
+ return null;
148
+ }
149
+
150
+ @Override
151
+ public void close() throws IOException {
152
+ ofStream.close();
153
+
154
+ }
155
+ }
156
+
157
+ }
@@ -1,19 +1,19 @@
1
- package com.ReactNativeBlobUtil.Utils;
2
-
3
- import android.webkit.MimeTypeMap;
4
-
5
- public class FileDescription {
6
- public String name;
7
- public String partentFolder;
8
- public String mimeType;
9
-
10
- public FileDescription(String n, String mT, String pF) {
11
- name = n;
12
- partentFolder = pF != null ? pF : "";
13
- mimeType = mT;
14
- }
15
-
16
- public String getFullPath(){
17
- return partentFolder + "/" + MimeType.getFullFileName(name, mimeType);
18
- }
19
- }
1
+ package com.ReactNativeBlobUtil.Utils;
2
+
3
+ import android.webkit.MimeTypeMap;
4
+
5
+ public class FileDescription {
6
+ public String name;
7
+ public String partentFolder;
8
+ public String mimeType;
9
+
10
+ public FileDescription(String n, String mT, String pF) {
11
+ name = n;
12
+ partentFolder = pF != null ? pF : "";
13
+ mimeType = mT;
14
+ }
15
+
16
+ public String getFullPath(){
17
+ return partentFolder + "/" + MimeType.getFullFileName(name, mimeType);
18
+ }
19
+ }
@@ -1,4 +1,4 @@
1
- package com.ReactNativeBlobUtil.Utils;
2
-
3
- public class FileProvider extends androidx.core.content.FileProvider {
4
- }
1
+ package com.ReactNativeBlobUtil.Utils;
2
+
3
+ public class FileProvider extends androidx.core.content.FileProvider {
4
+ }