react-native-blob-util 0.19.0 → 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,366 +1,379 @@
1
- #pragma once
2
- #include "NativeModules.h"
3
- #include <winrt/Windows.Foundation.h>
4
- #include <winrt/Windows.Security.Cryptography.h>
5
- #include <winrt/Windows.Security.Cryptography.Core.h>
6
- #include <winrt/Windows.Web.Http.Filters.h>
7
- #include <mutex>
8
-
9
- namespace Cryptography = winrt::Windows::Security::Cryptography;
10
- namespace CryptographyCore = winrt::Windows::Security::Cryptography::Core;
11
-
12
- enum struct EncodingOptions { UTF8, BASE64, ASCII, URI };
13
-
14
- struct CancellationDisposable
15
- {
16
- CancellationDisposable() = default;
17
- CancellationDisposable(winrt::Windows::Foundation::IAsyncInfo const& async, std::function<void()>&& onCancel) noexcept;
18
-
19
- CancellationDisposable(CancellationDisposable&& other) noexcept;
20
- CancellationDisposable& operator=(CancellationDisposable&& other) noexcept;
21
-
22
- CancellationDisposable(CancellationDisposable const&) = delete;
23
- CancellationDisposable& operator=(CancellationDisposable const&) = delete;
24
-
25
- ~CancellationDisposable() noexcept;
26
-
27
- void Cancel() noexcept;
28
- private:
29
- winrt::Windows::Foundation::IAsyncInfo m_async{ nullptr };
30
- std::function<void()> m_onCancel;
31
- };
32
-
33
- struct TaskCancellationManager
34
- {
35
- using TaskId = std::string;
36
-
37
- TaskCancellationManager() = default;
38
- ~TaskCancellationManager() noexcept;
39
-
40
- TaskCancellationManager(TaskCancellationManager const&) = delete;
41
- TaskCancellationManager& operator=(TaskCancellationManager const&) = delete;
42
-
43
- winrt::Windows::Foundation::IAsyncAction Add(TaskId taskId, winrt::Windows::Foundation::IAsyncAction const& asyncAction) noexcept;
44
- void Cancel(TaskId taskId) noexcept;
45
-
46
- private:
47
- std::mutex m_mutex; // to protect m_pendingTasks
48
- std::map<TaskId, CancellationDisposable> m_pendingTasks;
49
- };
50
-
51
- struct ReactNativeBlobUtilState
52
- {
53
- /*
54
-
55
- @"state": @"2", // store
56
- @"headers": headers, // store
57
- @"redirects": redirects, //check how to track, store
58
- @"respType" : respType, // store
59
- @"status": [NSNumber numberWithInteger : statusCode] // store
60
- */
61
- std::string state;
62
- winrt::Microsoft::ReactNative::JSValueObject headers;
63
- winrt::Microsoft::ReactNative::JSValueArray redirects;
64
- std::string respType;
65
- int status = 0;
66
-
67
- /*
68
- taskId: string;
69
- state: string;
70
- headers: any;
71
- redirects: string[];
72
- status: number;
73
- respType: "text" | "blob" | "" | "json";
74
- rnfbEncode: "path" | "base64" | "ascii" | "utf8";
75
- timeout: boolean;
76
- */
77
- };
78
-
79
-
80
- struct ReactNativeBlobUtilStream
81
- {
82
- public:
83
- ReactNativeBlobUtilStream(winrt::Windows::Storage::Streams::IRandomAccessStream& _streamInstance, EncodingOptions _encoding) noexcept;
84
- winrt::Windows::Storage::Streams::IRandomAccessStream streamInstance;
85
- const EncodingOptions encoding;
86
- };
87
-
88
- struct ReactNativeBlobUtilConfig
89
- {
90
- public:
91
- ReactNativeBlobUtilConfig(winrt::Microsoft::ReactNative::JSValueObject& options);
92
-
93
- bool overwrite;
94
- std::chrono::seconds timeout;
95
- bool trusty;
96
- bool fileCache;
97
- std::string key;
98
- std::string appendExt;
99
- std::string path;
100
- bool followRedirect;
101
- };
102
-
103
-
104
- struct ReactNativeBlobUtilProgressConfig {
105
- public:
106
- ReactNativeBlobUtilProgressConfig() = default;
107
- ReactNativeBlobUtilProgressConfig(int32_t count_, int32_t interval_);
108
-
109
- int64_t count{ -1 };
110
- int64_t interval{ -1 };
111
- };
112
-
113
-
114
- REACT_MODULE(ReactNativeBlobUtil, L"ReactNativeBlobUtil");
115
- struct ReactNativeBlobUtil : std::enable_shared_from_this<ReactNativeBlobUtil>
116
- {
117
- public:
118
- using StreamId = std::string;
119
-
120
- REACT_INIT(Initialize);
121
- void ReactNativeBlobUtil::Initialize(winrt::Microsoft::ReactNative::ReactContext const& reactContext) noexcept;
122
-
123
- REACT_CONSTANT_PROVIDER(ConstantsViaConstantsProvider);
124
- void ReactNativeBlobUtil::ConstantsViaConstantsProvider(
125
- winrt::Microsoft::ReactNative::ReactConstantProvider& constants) noexcept;
126
-
127
- // createFile
128
- REACT_METHOD(createFile);
129
- winrt::fire_and_forget createFile(
130
- std::string path,
131
- std::wstring content,
132
- std::string encoding,
133
- winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
134
-
135
- REACT_METHOD(createFileASCII);
136
- winrt::fire_and_forget createFileASCII(
137
- std::string path,
138
- winrt::Microsoft::ReactNative::JSValueArray dataArray,
139
- winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
140
-
141
-
142
- // writeFile
143
- REACT_METHOD(writeFile);
144
- winrt::fire_and_forget writeFile(
145
- std::string path,
146
- std::string encoding,
147
- std::wstring data,
148
- bool append,
149
- winrt::Microsoft::ReactNative::ReactPromise<int> promise) noexcept;
150
-
151
- REACT_METHOD(writeFileArray);
152
- winrt::fire_and_forget writeFileArray(
153
- std::string path,
154
- winrt::Microsoft::ReactNative::JSValueArray dataArray,
155
- bool append,
156
- winrt::Microsoft::ReactNative::ReactPromise<int> promise) noexcept;
157
-
158
- // writeStream
159
- REACT_METHOD(writeStream);
160
- winrt::fire_and_forget ReactNativeBlobUtil::writeStream(
161
- std::string path,
162
- std::string encoding,
163
- bool append,
164
- std::function<void(std::string, std::string, std::string)> callback) noexcept;
165
-
166
- // writeChunk
167
- REACT_METHOD(writeChunk);
168
- void ReactNativeBlobUtil::writeChunk(
169
- std::string streamId,
170
- std::wstring data,
171
- std::function<void(std::string)> callback) noexcept;
172
-
173
- REACT_METHOD(writeArrayChunk);
174
- void ReactNativeBlobUtil::writeArrayChunk(
175
- std::string streamId,
176
- winrt::Microsoft::ReactNative::JSValueArray dataArray,
177
- std::function<void(std::string)> callback) noexcept;
178
-
179
- // readStream
180
- REACT_METHOD(readStream);
181
- void ReactNativeBlobUtil::readStream(
182
- std::string path,
183
- std::string encoding,
184
- uint32_t bufferSize,
185
- uint64_t tick,
186
- const std::string streamId) noexcept;
187
-
188
-
189
- // mkdir
190
- REACT_METHOD(mkdir);
191
- void mkdir(
192
- std::string path,
193
- winrt::Microsoft::ReactNative::ReactPromise<bool> promise) noexcept;
194
-
195
-
196
- // readFile
197
- REACT_METHOD(readFile);
198
- winrt::fire_and_forget readFile(
199
- std::string path,
200
- std::string encoding,
201
- winrt::Microsoft::ReactNative::ReactPromise<std::wstring> promise) noexcept;
202
-
203
-
204
- // hash
205
- REACT_METHOD(hash);
206
- winrt::fire_and_forget hash(
207
- std::string path,
208
- std::string algorithm,
209
- winrt::Microsoft::ReactNative::ReactPromise<std::wstring> promise) noexcept;
210
-
211
- // ls
212
- REACT_METHOD(ls);
213
- winrt::fire_and_forget ls(
214
- std::string path,
215
- winrt::Microsoft::ReactNative::ReactPromise<std::vector<std::string>> promise) noexcept;
216
-
217
-
218
- // mv
219
- REACT_METHOD(mv);
220
- winrt::fire_and_forget mv(
221
- std::string src, // from
222
- std::string dest, // to
223
- std::function<void(std::string)> callback) noexcept;
224
-
225
-
226
- // cp
227
- REACT_METHOD(cp);
228
- winrt::fire_and_forget cp(
229
- std::string src, // from
230
- std::string dest, // to
231
- std::function<void(std::string)> callback) noexcept;
232
-
233
-
234
- // exists
235
- REACT_METHOD(exists);
236
- void exists(
237
- std::string path,
238
- std::function<void(bool, bool)> callback) noexcept;
239
-
240
-
241
- // unlink
242
- REACT_METHOD(unlink);
243
- winrt::fire_and_forget unlink(
244
- std::string path,
245
- std::function<void(std::string, bool)> callback) noexcept;
246
-
247
-
248
- // lstat
249
- REACT_METHOD(lstat);
250
- winrt::fire_and_forget lstat(
251
- std::string path,
252
- std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueArray&)> callback) noexcept;
253
-
254
-
255
- // stat
256
- REACT_METHOD(stat);
257
- winrt::fire_and_forget stat(
258
- std::string path,
259
- std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueObject&)> callback) noexcept;
260
-
261
- // df
262
- REACT_METHOD(df);
263
- winrt::fire_and_forget df(
264
- std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueObject&)> callback) noexcept;
265
-
266
- REACT_METHOD(slice);
267
- winrt::fire_and_forget ReactNativeBlobUtil::slice(
268
- std::string src,
269
- std::string dest,
270
- uint32_t start,
271
- uint32_t end,
272
- winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
273
-
274
- REACT_METHOD(fetchBlob);
275
- winrt::fire_and_forget fetchBlob(
276
- winrt::Microsoft::ReactNative::JSValueObject options,
277
- std::string taskId,
278
- std::string method,
279
- std::wstring url,
280
- winrt::Microsoft::ReactNative::JSValueObject headers,
281
- std::string body,
282
- std::function<void(std::string, std::string, std::string)> callback) noexcept;
283
-
284
- REACT_METHOD(fetchBlobForm);
285
- winrt::fire_and_forget fetchBlobForm(
286
- winrt::Microsoft::ReactNative::JSValueObject options,
287
- std::string taskId,
288
- std::string method,
289
- std::wstring url,
290
- winrt::Microsoft::ReactNative::JSValueObject headers,
291
- winrt::Microsoft::ReactNative::JSValueArray body,
292
- std::function<void(std::string, std::string, std::string)> callback) noexcept;
293
-
294
- REACT_METHOD(enableProgressReport);
295
- void enableProgressReport(
296
- std::string taskId,
297
- int interval,
298
- int count) noexcept;
299
-
300
- // enableUploadProgressReport
301
- REACT_METHOD(enableUploadProgressReport);
302
- void enableUploadProgressReport(
303
- std::string taskId,
304
- int interval,
305
- int count) noexcept;
306
-
307
- // cancelRequest
308
- REACT_METHOD(cancelRequest);
309
- void cancelRequest(
310
- std::string taskId,
311
- std::function<void(std::string, std::string)> callback) noexcept;
312
-
313
- REACT_METHOD(removeSession);
314
- winrt::fire_and_forget ReactNativeBlobUtil::removeSession(
315
- winrt::Microsoft::ReactNative::JSValueArray paths,
316
- std::function<void(std::string)> callback) noexcept;
317
-
318
- REACT_METHOD(closeStream);
319
- void closeStream(
320
- std::string streamId,
321
- std::function<void(std::string)> callback) noexcept;
322
-
323
- // Helper methods
324
- private:
325
-
326
-
327
- constexpr static int64_t UNIX_EPOCH_IN_WINRT_SECONDS = 11644473600;
328
-
329
- std::map<StreamId, ReactNativeBlobUtilStream> m_streamMap;
330
- //winrt::Windows::Web::Http::HttpClient m_httpClient;
331
- winrt::Microsoft::ReactNative::ReactContext m_reactContext;
332
- TaskCancellationManager m_tasks;
333
-
334
- winrt::Windows::Foundation::IAsyncAction ProcessRequestAsync(
335
- const std::string& taskId,
336
- const winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter& filter,
337
- winrt::Windows::Web::Http::HttpRequestMessage& httpRequestMessage,
338
- ReactNativeBlobUtilConfig& config,
339
- std::function<void(std::string, std::string, std::string)> callback,
340
- std::string& error) noexcept;
341
-
342
- const std::map<std::string, std::function<CryptographyCore::HashAlgorithmProvider()>> availableHashes{
343
- {"md5", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Md5()); } },
344
- {"sha1", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha1()); } },
345
- {"sha256", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha256()); } },
346
- {"sha384", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha384()); } },
347
- {"sha512", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha512()); } }
348
- };
349
-
350
- void splitPath(const std::string& fullPath,
351
- winrt::hstring& directoryPath,
352
- winrt::hstring& fileName) noexcept;
353
-
354
- void splitPath(const std::wstring& fullPath,
355
- winrt::hstring& directoryPath,
356
- winrt::hstring& fileName) noexcept;
357
-
358
- const std::string prefix{ "ReactNativeBlobUtil-file://" };
359
-
360
- std::mutex m_mutex;
361
- std::map<std::string, ReactNativeBlobUtilProgressConfig> downloadProgressMap;
362
- std::map<std::string, ReactNativeBlobUtilProgressConfig> uploadProgressMap;
363
- };
364
-
365
-
366
-
1
+ #pragma once
2
+ #include "NativeModules.h"
3
+ #include <winrt/Windows.Foundation.h>
4
+ #include <winrt/Windows.Security.Cryptography.h>
5
+ #include <winrt/Windows.Security.Cryptography.Core.h>
6
+ #include <winrt/Windows.Web.Http.Filters.h>
7
+ #include <mutex>
8
+
9
+ namespace Cryptography = winrt::Windows::Security::Cryptography;
10
+ namespace CryptographyCore = winrt::Windows::Security::Cryptography::Core;
11
+
12
+ enum struct EncodingOptions { UTF8, BASE64, ASCII, URI };
13
+
14
+ struct CancellationDisposable
15
+ {
16
+ CancellationDisposable() = default;
17
+ CancellationDisposable(winrt::Windows::Foundation::IAsyncInfo const& async, std::function<void()>&& onCancel) noexcept;
18
+
19
+ CancellationDisposable(CancellationDisposable&& other) noexcept;
20
+ CancellationDisposable& operator=(CancellationDisposable&& other) noexcept;
21
+
22
+ CancellationDisposable(CancellationDisposable const&) = delete;
23
+ CancellationDisposable& operator=(CancellationDisposable const&) = delete;
24
+
25
+ ~CancellationDisposable() noexcept;
26
+
27
+ void Cancel() noexcept;
28
+ private:
29
+ winrt::Windows::Foundation::IAsyncInfo m_async{ nullptr };
30
+ std::function<void()> m_onCancel;
31
+ };
32
+
33
+ struct TaskCancellationManager
34
+ {
35
+ using TaskId = std::string;
36
+
37
+ TaskCancellationManager() = default;
38
+ ~TaskCancellationManager() noexcept;
39
+
40
+ TaskCancellationManager(TaskCancellationManager const&) = delete;
41
+ TaskCancellationManager& operator=(TaskCancellationManager const&) = delete;
42
+
43
+ winrt::Windows::Foundation::IAsyncAction Add(TaskId taskId, winrt::Windows::Foundation::IAsyncAction const& asyncAction) noexcept;
44
+ void Cancel(TaskId taskId) noexcept;
45
+
46
+ private:
47
+ std::mutex m_mutex; // to protect m_pendingTasks
48
+ std::map<TaskId, CancellationDisposable> m_pendingTasks;
49
+ };
50
+
51
+ struct ReactNativeBlobUtilState
52
+ {
53
+ /*
54
+
55
+ @"state": @"2", // store
56
+ @"headers": headers, // store
57
+ @"redirects": redirects, //check how to track, store
58
+ @"respType" : respType, // store
59
+ @"status": [NSNumber numberWithInteger : statusCode] // store
60
+ */
61
+ std::string state;
62
+ winrt::Microsoft::ReactNative::JSValueObject headers;
63
+ winrt::Microsoft::ReactNative::JSValueArray redirects;
64
+ std::string respType;
65
+ int status = 0;
66
+
67
+ /*
68
+ taskId: string;
69
+ state: string;
70
+ headers: any;
71
+ redirects: string[];
72
+ status: number;
73
+ respType: "text" | "blob" | "" | "json";
74
+ rnfbEncode: "path" | "base64" | "ascii" | "utf8";
75
+ timeout: boolean;
76
+ */
77
+ };
78
+
79
+
80
+ struct ReactNativeBlobUtilStream
81
+ {
82
+ public:
83
+ ReactNativeBlobUtilStream(winrt::Windows::Storage::Streams::IRandomAccessStream& _streamInstance, EncodingOptions _encoding) noexcept;
84
+ winrt::Windows::Storage::Streams::IRandomAccessStream streamInstance;
85
+ const EncodingOptions encoding;
86
+ };
87
+
88
+ struct ReactNativeBlobUtilConfig
89
+ {
90
+ public:
91
+ ReactNativeBlobUtilConfig(winrt::Microsoft::ReactNative::JSValueObject& options);
92
+
93
+ bool overwrite;
94
+ std::chrono::seconds timeout;
95
+ bool trusty;
96
+ bool fileCache;
97
+ std::string key;
98
+ std::string appendExt;
99
+ std::string path;
100
+ bool followRedirect;
101
+ };
102
+
103
+
104
+ struct ReactNativeBlobUtilProgressConfig {
105
+ public:
106
+ ReactNativeBlobUtilProgressConfig() = default;
107
+ ReactNativeBlobUtilProgressConfig(int32_t count_, int32_t interval_);
108
+
109
+ int64_t count{ -1 };
110
+ int64_t interval{ -1 };
111
+ };
112
+
113
+
114
+ REACT_MODULE(ReactNativeBlobUtil, L"ReactNativeBlobUtil");
115
+ struct ReactNativeBlobUtil : std::enable_shared_from_this<ReactNativeBlobUtil>
116
+ {
117
+ public:
118
+ using StreamId = std::string;
119
+
120
+ REACT_INIT(Initialize);
121
+ void ReactNativeBlobUtil::Initialize(winrt::Microsoft::ReactNative::ReactContext const& reactContext) noexcept;
122
+
123
+ REACT_CONSTANT_PROVIDER(ConstantsViaConstantsProvider);
124
+ void ReactNativeBlobUtil::ConstantsViaConstantsProvider(
125
+ winrt::Microsoft::ReactNative::ReactConstantProvider& constants) noexcept;
126
+
127
+ // createFile
128
+ REACT_METHOD(createFile);
129
+ winrt::fire_and_forget createFile(
130
+ std::string path,
131
+ std::wstring content,
132
+ std::string encoding,
133
+ winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
134
+
135
+ REACT_METHOD(createFileASCII);
136
+ winrt::fire_and_forget createFileASCII(
137
+ std::string path,
138
+ winrt::Microsoft::ReactNative::JSValueArray dataArray,
139
+ winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
140
+
141
+
142
+ // writeFile
143
+ REACT_METHOD(writeFile);
144
+ winrt::fire_and_forget writeFile(
145
+ std::string path,
146
+ std::string encoding,
147
+ std::wstring data,
148
+ bool append,
149
+ winrt::Microsoft::ReactNative::ReactPromise<int> promise) noexcept;
150
+
151
+ REACT_METHOD(writeFileArray);
152
+ winrt::fire_and_forget writeFileArray(
153
+ std::string path,
154
+ winrt::Microsoft::ReactNative::JSValueArray dataArray,
155
+ bool append,
156
+ winrt::Microsoft::ReactNative::ReactPromise<int> promise) noexcept;
157
+
158
+ // writeStream
159
+ REACT_METHOD(writeStream);
160
+ winrt::fire_and_forget ReactNativeBlobUtil::writeStream(
161
+ std::string path,
162
+ std::string encoding,
163
+ bool append,
164
+ std::function<void(std::string, std::string, std::string)> callback) noexcept;
165
+
166
+ // writeChunk
167
+ REACT_METHOD(writeChunk);
168
+ void ReactNativeBlobUtil::writeChunk(
169
+ std::string streamId,
170
+ std::wstring data,
171
+ std::function<void(std::string)> callback) noexcept;
172
+
173
+ REACT_METHOD(writeArrayChunk);
174
+ void ReactNativeBlobUtil::writeArrayChunk(
175
+ std::string streamId,
176
+ winrt::Microsoft::ReactNative::JSValueArray dataArray,
177
+ std::function<void(std::string)> callback) noexcept;
178
+
179
+ // readStream
180
+ REACT_METHOD(readStream);
181
+ void ReactNativeBlobUtil::readStream(
182
+ std::string path,
183
+ std::string encoding,
184
+ uint32_t bufferSize,
185
+ uint64_t tick,
186
+ const std::string streamId) noexcept;
187
+
188
+
189
+ // mkdir
190
+ REACT_METHOD(mkdir);
191
+ void mkdir(
192
+ std::string path,
193
+ winrt::Microsoft::ReactNative::ReactPromise<bool> promise) noexcept;
194
+
195
+
196
+ // readFile
197
+ REACT_METHOD(readFile);
198
+ winrt::fire_and_forget readFile(
199
+ std::string path,
200
+ std::string encoding,
201
+ winrt::Microsoft::ReactNative::ReactPromise<std::wstring> promise) noexcept;
202
+
203
+
204
+ // hash
205
+ REACT_METHOD(hash);
206
+ winrt::fire_and_forget hash(
207
+ std::string path,
208
+ std::string algorithm,
209
+ winrt::Microsoft::ReactNative::ReactPromise<std::wstring> promise) noexcept;
210
+
211
+ // ls
212
+ REACT_METHOD(ls);
213
+ winrt::fire_and_forget ls(
214
+ std::string path,
215
+ winrt::Microsoft::ReactNative::ReactPromise<std::vector<std::string>> promise) noexcept;
216
+
217
+
218
+ // mv
219
+ REACT_METHOD(mv);
220
+ winrt::fire_and_forget mv(
221
+ std::string src, // from
222
+ std::string dest, // to
223
+ std::function<void(std::string)> callback) noexcept;
224
+
225
+
226
+ // cp
227
+ REACT_METHOD(cp);
228
+ winrt::fire_and_forget cp(
229
+ std::string src, // from
230
+ std::string dest, // to
231
+ std::function<void(std::string)> callback) noexcept;
232
+
233
+
234
+ // exists
235
+ REACT_METHOD(exists);
236
+ void exists(
237
+ std::string path,
238
+ std::function<void(bool, bool)> callback) noexcept;
239
+
240
+
241
+ // unlink
242
+ REACT_METHOD(unlink);
243
+ winrt::fire_and_forget unlink(
244
+ std::string path,
245
+ std::function<void(std::string, bool)> callback) noexcept;
246
+
247
+
248
+ // lstat
249
+ REACT_METHOD(lstat);
250
+ winrt::fire_and_forget lstat(
251
+ std::string path,
252
+ std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueArray&)> callback) noexcept;
253
+
254
+
255
+ // stat
256
+ REACT_METHOD(stat);
257
+ winrt::fire_and_forget stat(
258
+ std::string path,
259
+ std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueObject&)> callback) noexcept;
260
+
261
+ // df
262
+ REACT_METHOD(df);
263
+ winrt::fire_and_forget df(
264
+ std::function<void(std::string, winrt::Microsoft::ReactNative::JSValueObject&)> callback) noexcept;
265
+
266
+ REACT_METHOD(slice);
267
+ winrt::fire_and_forget ReactNativeBlobUtil::slice(
268
+ std::string src,
269
+ std::string dest,
270
+ uint32_t start,
271
+ uint32_t end,
272
+ winrt::Microsoft::ReactNative::ReactPromise<std::string> promise) noexcept;
273
+
274
+ REACT_METHOD(fetchBlob);
275
+ winrt::fire_and_forget fetchBlob(
276
+ winrt::Microsoft::ReactNative::JSValueObject options,
277
+ std::string taskId,
278
+ std::string method,
279
+ std::wstring url,
280
+ winrt::Microsoft::ReactNative::JSValueObject headers,
281
+ std::string body,
282
+ std::function<void(std::string, std::string, std::string)> callback) noexcept;
283
+
284
+ REACT_METHOD(fetchBlobForm);
285
+ winrt::fire_and_forget fetchBlobForm(
286
+ winrt::Microsoft::ReactNative::JSValueObject options,
287
+ std::string taskId,
288
+ std::string method,
289
+ std::wstring url,
290
+ winrt::Microsoft::ReactNative::JSValueObject headers,
291
+ winrt::Microsoft::ReactNative::JSValueArray body,
292
+ std::function<void(std::string, std::string, std::string)> callback) noexcept;
293
+
294
+ REACT_METHOD(enableProgressReport);
295
+ void enableProgressReport(
296
+ std::string taskId,
297
+ int interval,
298
+ int count) noexcept;
299
+
300
+ // enableUploadProgressReport
301
+ REACT_METHOD(enableUploadProgressReport);
302
+ void enableUploadProgressReport(
303
+ std::string taskId,
304
+ int interval,
305
+ int count) noexcept;
306
+
307
+ // cancelRequest
308
+ REACT_METHOD(cancelRequest);
309
+ void cancelRequest(
310
+ std::string taskId,
311
+ std::function<void(std::string, std::string)> callback) noexcept;
312
+
313
+ REACT_METHOD(removeSession);
314
+ winrt::fire_and_forget ReactNativeBlobUtil::removeSession(
315
+ winrt::Microsoft::ReactNative::JSValueArray paths,
316
+ std::function<void(std::string)> callback) noexcept;
317
+
318
+ REACT_METHOD(closeStream);
319
+ void closeStream(
320
+ std::string streamId,
321
+ std::function<void(std::string)> callback) noexcept;
322
+
323
+ // addListener
324
+ REACT_METHOD(addListener);
325
+ void addListener(
326
+ std::string eventName
327
+ ) noexcept;
328
+
329
+ // removeListeners
330
+ REACT_METHOD(removeListeners);
331
+ void removeListeners(
332
+ double count
333
+ ) noexcept;
334
+
335
+
336
+ // Helper methods
337
+ private:
338
+
339
+
340
+ constexpr static int64_t UNIX_EPOCH_IN_WINRT_SECONDS = 11644473600;
341
+
342
+ std::map<StreamId, ReactNativeBlobUtilStream> m_streamMap;
343
+ //winrt::Windows::Web::Http::HttpClient m_httpClient;
344
+ winrt::Microsoft::ReactNative::ReactContext m_reactContext;
345
+ TaskCancellationManager m_tasks;
346
+
347
+ winrt::Windows::Foundation::IAsyncAction ProcessRequestAsync(
348
+ const std::string& taskId,
349
+ const winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter& filter,
350
+ winrt::Windows::Web::Http::HttpRequestMessage& httpRequestMessage,
351
+ ReactNativeBlobUtilConfig& config,
352
+ std::function<void(std::string, std::string, std::string)> callback,
353
+ std::string& error) noexcept;
354
+
355
+ const std::map<std::string, std::function<CryptographyCore::HashAlgorithmProvider()>> availableHashes{
356
+ {"md5", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Md5()); } },
357
+ {"sha1", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha1()); } },
358
+ {"sha256", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha256()); } },
359
+ {"sha384", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha384()); } },
360
+ {"sha512", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha512()); } }
361
+ };
362
+
363
+ void splitPath(const std::string& fullPath,
364
+ winrt::hstring& directoryPath,
365
+ winrt::hstring& fileName) noexcept;
366
+
367
+ void splitPath(const std::wstring& fullPath,
368
+ winrt::hstring& directoryPath,
369
+ winrt::hstring& fileName) noexcept;
370
+
371
+ const std::string prefix{ "ReactNativeBlobUtil-file://" };
372
+
373
+ std::mutex m_mutex;
374
+ std::map<std::string, ReactNativeBlobUtilProgressConfig> downloadProgressMap;
375
+ std::map<std::string, ReactNativeBlobUtilProgressConfig> uploadProgressMap;
376
+ };
377
+
378
+
379
+