react-native-blob-util 0.21.2 → 0.22.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.
Files changed (98) hide show
  1. package/.eslintrc.js +56 -56
  2. package/LICENSE +21 -21
  3. package/Migration.md +41 -41
  4. package/NuGet.config +11 -0
  5. package/README.md +1104 -1095
  6. package/android/gradle.properties +1 -1
  7. package/android/src/main/AndroidManifest.xml +37 -37
  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/ReactNativeBlobUtilFileTransformer.java +9 -9
  11. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.java +431 -431
  12. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilProgressConfig.java +39 -39
  13. package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +1014 -1014
  14. package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilDefaultResp.java +98 -98
  15. package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +166 -157
  16. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -19
  17. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileProvider.java +4 -4
  18. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -70
  19. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/PathResolver.java +223 -223
  20. package/android/src/main/java/com/ReactNativeBlobUtil/Utils/Tls12SocketFactory.java +68 -68
  21. package/android/src/main/res/values/strings.xml +3 -3
  22. package/android/src/main/res/xml/provider_paths.xml +12 -12
  23. package/android.js +58 -58
  24. package/class/ReactNativeBlobUtilCanceledFetchError.js +9 -9
  25. package/class/ReactNativeBlobUtilFile.js +5 -5
  26. package/class/ReactNativeBlobUtilReadStream.js +84 -84
  27. package/class/ReactNativeBlobUtilSession.js +68 -68
  28. package/class/ReactNativeBlobUtilWriteStream.js +50 -50
  29. package/class/StatefulPromise.js +7 -7
  30. package/codegenSpecs/NativeBlobUtils.js +86 -86
  31. package/components/Fetch.onPress.js +10 -10
  32. package/components/Fetch.when.js +15 -15
  33. package/fetch.js +350 -350
  34. package/fs.js +480 -480
  35. package/index.js +64 -64
  36. package/index.js.flow +192 -192
  37. package/index.web.js +1 -1
  38. package/ios/PrivacyInfo.xcprivacy +28 -28
  39. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +55 -55
  40. package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +992 -992
  41. package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +405 -405
  42. package/ios/ReactNativeBlobUtilConst.h +58 -58
  43. package/ios/ReactNativeBlobUtilConst.mm +47 -47
  44. package/ios/ReactNativeBlobUtilFS.h +108 -108
  45. package/ios/ReactNativeBlobUtilFS.mm +1064 -1064
  46. package/ios/ReactNativeBlobUtilFileTransformer.h +23 -23
  47. package/ios/ReactNativeBlobUtilFileTransformer.mm +20 -20
  48. package/ios/ReactNativeBlobUtilNetwork.h +49 -49
  49. package/ios/ReactNativeBlobUtilNetwork.mm +159 -159
  50. package/ios/ReactNativeBlobUtilProgress.h +32 -32
  51. package/ios/ReactNativeBlobUtilProgress.mm +57 -57
  52. package/ios/ReactNativeBlobUtilReqBuilder.h +37 -37
  53. package/ios/ReactNativeBlobUtilReqBuilder.mm +292 -292
  54. package/ios/ReactNativeBlobUtilRequest.h +48 -48
  55. package/ios/ReactNativeBlobUtilRequest.mm +584 -584
  56. package/ios.js +61 -61
  57. package/json-stream.js +42 -42
  58. package/lib/oboe-browser.js +2703 -2703
  59. package/mediacollection.js +36 -36
  60. package/package.json +68 -55
  61. package/polyfill/Blob.js +362 -362
  62. package/polyfill/Event.js +11 -11
  63. package/polyfill/EventTarget.js +78 -78
  64. package/polyfill/Fetch.js +219 -219
  65. package/polyfill/File.js +27 -27
  66. package/polyfill/FileReader.js +91 -91
  67. package/polyfill/ProgressEvent.js +32 -32
  68. package/polyfill/XMLHttpRequest.js +466 -466
  69. package/polyfill/XMLHttpRequestEventTarget.js +126 -126
  70. package/polyfill/index.js +11 -11
  71. package/react-native-blob-util.podspec +48 -48
  72. package/types.js +69 -69
  73. package/utils/log.js +40 -40
  74. package/utils/unicode.js +7 -7
  75. package/utils/uri.js +33 -33
  76. package/utils/uuid.js +4 -4
  77. package/windows/ExperimentalFeatures.props +33 -0
  78. package/windows/README.md +2 -2
  79. package/windows/ReactNativeBlobUtil/PropertySheet.props +15 -15
  80. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.cpp +1837 -1701
  81. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.def +3 -3
  82. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.h +373 -379
  83. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.rc +0 -0
  84. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj +140 -181
  85. package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj.filters +43 -31
  86. package/windows/ReactNativeBlobUtil/ReactPackageProvider.cpp +20 -15
  87. package/windows/ReactNativeBlobUtil/ReactPackageProvider.h +24 -20
  88. package/windows/ReactNativeBlobUtil/ReactPackageProvider.idl +9 -9
  89. package/windows/ReactNativeBlobUtil/codegen/.clang-format +2 -0
  90. package/windows/ReactNativeBlobUtil/codegen/NativeBlobUtilsDataTypes.g.h +42 -0
  91. package/windows/ReactNativeBlobUtil/codegen/NativeBlobUtilsSpec.g.h +353 -0
  92. package/windows/ReactNativeBlobUtil/packages.config +3 -3
  93. package/windows/ReactNativeBlobUtil/packages.lock.json +60 -0
  94. package/windows/ReactNativeBlobUtil/pch.cpp +1 -1
  95. package/windows/ReactNativeBlobUtil/pch.h +30 -4
  96. package/windows/ReactNativeBlobUtil/resource.h +5 -0
  97. package/windows/ReactNativeBlobUtil/targetver.h +8 -0
  98. package/windows/ReactNativeBlobUtil.sln +43 -0
@@ -1,379 +1,373 @@
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
-
1
+ #pragma once
2
+
3
+ #include "pch.h"
4
+ #include "resource.h"
5
+
6
+ #if __has_include("codegen/NativeBlobUtilsDataTypes.g.h")
7
+ #include "codegen/NativeBlobUtilsDataTypes.g.h"
8
+ #endif
9
+
10
+ #include "codegen/NativeBlobUtilsSpec.g.h"
11
+ #include "NativeModules.h"
12
+ #include <winrt/Windows.Foundation.h>
13
+ #include <winrt/Windows.Security.Cryptography.h>
14
+ #include <winrt/Windows.Security.Cryptography.Core.h>
15
+ #include <winrt/Windows.Web.Http.Filters.h>
16
+ #include <mutex>
17
+
18
+ namespace Cryptography = winrt::Windows::Security::Cryptography;
19
+ namespace CryptographyCore = winrt::Windows::Security::Cryptography::Core;
20
+
21
+ enum struct EncodingOptions { UTF8, BASE64, ASCII, URI };
22
+
23
+ struct CancellationDisposable
24
+ {
25
+ CancellationDisposable() = default;
26
+ CancellationDisposable(winrt::Windows::Foundation::IAsyncInfo const& async, std::function<void()>&& onCancel) noexcept;
27
+
28
+ CancellationDisposable(CancellationDisposable&& other) noexcept;
29
+ CancellationDisposable& operator=(CancellationDisposable&& other) noexcept;
30
+
31
+ CancellationDisposable(CancellationDisposable const&) = delete;
32
+ CancellationDisposable& operator=(CancellationDisposable const&) = delete;
33
+
34
+ ~CancellationDisposable() noexcept;
35
+
36
+ void Cancel() noexcept;
37
+ private:
38
+ winrt::Windows::Foundation::IAsyncInfo m_async{ nullptr };
39
+ std::function<void()> m_onCancel;
40
+ };
41
+
42
+ struct TaskCancellationManager
43
+ {
44
+ using TaskId = std::string;
45
+
46
+ TaskCancellationManager() = default;
47
+ ~TaskCancellationManager() noexcept;
48
+
49
+ TaskCancellationManager(TaskCancellationManager const&) = delete;
50
+ TaskCancellationManager& operator=(TaskCancellationManager const&) = delete;
51
+
52
+ winrt::Windows::Foundation::IAsyncAction Add(TaskId taskId, winrt::Windows::Foundation::IAsyncAction const& asyncAction) noexcept;
53
+ void Cancel(TaskId taskId) noexcept;
54
+
55
+ private:
56
+ std::mutex m_mutex; // to protect m_pendingTasks
57
+ std::map<TaskId, CancellationDisposable> m_pendingTasks;
58
+ };
59
+
60
+ struct ReactNativeBlobUtilState
61
+ {
62
+ /*
63
+
64
+ @"state": @"2", // store
65
+ @"headers": headers, // store
66
+ @"redirects": redirects, //check how to track, store
67
+ @"respType" : respType, // store
68
+ @"status": [NSNumber numberWithInteger : statusCode] // store
69
+ */
70
+ std::string state;
71
+ winrt::Microsoft::ReactNative::JSValueObject headers;
72
+ winrt::Microsoft::ReactNative::JSValueArray redirects;
73
+ std::string respType;
74
+ int status = 0;
75
+
76
+ /*
77
+ taskId: string;
78
+ state: string;
79
+ headers: any;
80
+ redirects: string[];
81
+ status: number;
82
+ respType: "text" | "blob" | "" | "json";
83
+ rnfbEncode: "path" | "base64" | "ascii" | "utf8";
84
+ timeout: boolean;
85
+ */
86
+ };
87
+
88
+
89
+ struct ReactNativeBlobUtilStream
90
+ {
91
+ public:
92
+ ReactNativeBlobUtilStream(winrt::Windows::Storage::Streams::IRandomAccessStream& _streamInstance, EncodingOptions _encoding) noexcept;
93
+ winrt::Windows::Storage::Streams::IRandomAccessStream streamInstance;
94
+ const EncodingOptions encoding;
95
+ };
96
+
97
+ struct ReactNativeBlobUtilConfig
98
+ {
99
+ public:
100
+ ReactNativeBlobUtilConfig(::React::JSValue& options);
101
+
102
+ bool overwrite;
103
+ std::chrono::seconds timeout;
104
+ bool trusty;
105
+ bool fileCache;
106
+ std::string key;
107
+ std::string appendExt;
108
+ std::string path;
109
+ bool followRedirect;
110
+ };
111
+
112
+
113
+ struct ReactNativeBlobUtilProgressConfig {
114
+ public:
115
+ ReactNativeBlobUtilProgressConfig() = default;
116
+ ReactNativeBlobUtilProgressConfig(double count_, double interval_);
117
+
118
+ double count{ -1.0 };
119
+ double interval{ -1.0 };
120
+ };
121
+
122
+ namespace winrt::ReactNativeBlobUtil
123
+ {
124
+
125
+ REACT_MODULE(ReactNativeBlobUtil)
126
+ struct ReactNativeBlobUtil
127
+ {
128
+ using ModuleSpec = ReactNativeBlobUtilCodegen::BlobUtilsSpec;
129
+ using StreamId = std::string;
130
+
131
+ REACT_INIT(Initialize)
132
+ void Initialize(React::ReactContext const& reactContext) noexcept;
133
+
134
+ REACT_GET_CONSTANTS(GetConstants)
135
+ ReactNativeBlobUtilCodegen::BlobUtilsSpec_Constants GetConstants() noexcept;
136
+
137
+ REACT_METHOD(fetchBlobForm)
138
+ winrt::fire_and_forget fetchBlobForm(::React::JSValue options, std::string taskId, std::string method, std::string url, ::React::JSValue headers, ::React::JSValueArray form, std::function<void(::React::JSValueArray)> callback) noexcept;
139
+
140
+ REACT_METHOD(fetchBlob)
141
+ winrt::fire_and_forget fetchBlob(::React::JSValue options, std::string taskId, std::string method, std::string url, ::React::JSValue headers, std::string body, std::function<void(::React::JSValueArray)> callback) noexcept;
142
+
143
+ REACT_METHOD(createFile)
144
+ winrt::fire_and_forget createFile(
145
+ std::string path,
146
+ std::wstring content,
147
+ std::string encoding,
148
+ winrt::Microsoft::ReactNative::ReactPromise<void> promise
149
+ ) noexcept;
150
+
151
+ REACT_METHOD(createFileASCII)
152
+ winrt::fire_and_forget createFileASCII(
153
+ std::string path,
154
+ winrt::Microsoft::ReactNative::JSValueArray dataArray,
155
+ winrt::Microsoft::ReactNative::ReactPromise<void> promise) noexcept;
156
+
157
+ REACT_METHOD(writeFile)
158
+ winrt::fire_and_forget writeFile(
159
+ std::string path,
160
+ std::string encoding,
161
+ std::wstring data,
162
+ bool transformFile,
163
+ bool append,
164
+ winrt::Microsoft::ReactNative::ReactPromise<double> promise) noexcept;
165
+
166
+ REACT_METHOD(writeFileArray)
167
+ winrt::fire_and_forget writeFileArray(
168
+ std::string path,
169
+ winrt::Microsoft::ReactNative::JSValueArray dataArray,
170
+ bool append,
171
+ winrt::Microsoft::ReactNative::ReactPromise<double> promise) noexcept;
172
+
173
+ REACT_METHOD(pathForAppGroup)
174
+ void pathForAppGroup(std::string groupName, ::React::ReactPromise<std::string>&& result) noexcept;
175
+
176
+ REACT_SYNC_METHOD(syncPathAppGroup)
177
+ std::string syncPathAppGroup(std::string groupName) noexcept;
178
+
179
+ REACT_METHOD(exists)
180
+ void exists(std::string path, std::function<void(std::vector<bool> const&)> const& callback) noexcept;
181
+
182
+ REACT_METHOD(writeStream)
183
+ winrt::fire_and_forget writeStream(std::string path, std::string encoding, bool appendData, std::function<void(::React::JSValueArray)> callback) noexcept;
184
+
185
+ REACT_METHOD(writeArrayChunk)
186
+ void writeArrayChunk(std::string streamId, ::React::JSValueArray&& dataArray, std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
187
+
188
+ REACT_METHOD(writeChunk)
189
+ void writeChunk(std::string streamId, std::string data, std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
190
+
191
+ REACT_METHOD(closeStream)
192
+ void closeStream(std::string streamId, std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
193
+
194
+ REACT_METHOD(unlink)
195
+ winrt::fire_and_forget unlink(std::string path, std::function<void(::React::JSValueArray)> callback) noexcept;
196
+
197
+ REACT_METHOD(removeSession)
198
+ winrt::fire_and_forget removeSession(::React::JSValueArray paths, std::function<void(::React::JSValueArray)> callback) noexcept;
199
+
200
+ // readFile
201
+ REACT_METHOD(readFile)
202
+ winrt::fire_and_forget readFile(
203
+ std::string path,
204
+ std::string encoding,
205
+ bool transformFile,
206
+ ::React::ReactPromise<::React::JSValueArray> promise) noexcept;
207
+
208
+ // hash
209
+ REACT_METHOD(hash)
210
+ winrt::fire_and_forget hash(
211
+ std::string path,
212
+ std::string algorithm,
213
+ ::React::ReactPromise<std::string> promise) noexcept;
214
+
215
+ // ls
216
+ REACT_METHOD(ls)
217
+ winrt::fire_and_forget ls(
218
+ std::string path,
219
+ ::React::ReactPromise<::React::JSValueArray> promise) noexcept;
220
+
221
+ // mv
222
+ REACT_METHOD(mv)
223
+ winrt::fire_and_forget mv(
224
+ std::string src,
225
+ std::string dest,
226
+ std::function<void(::React::JSValueArray)> callback) noexcept;
227
+
228
+ // cp
229
+ REACT_METHOD(cp)
230
+ winrt::fire_and_forget cp(
231
+ std::string src, // from
232
+ std::string dest, // to
233
+ std::function<void(::React::JSValueArray)> callback) noexcept;
234
+
235
+ // lstat
236
+ REACT_METHOD(lstat)
237
+ winrt::fire_and_forget lstat(
238
+ std::string path,
239
+ std::function<void(::React::JSValueArray)> callback) noexcept;
240
+
241
+ // stat
242
+ REACT_METHOD(stat)
243
+ winrt::fire_and_forget stat(
244
+ std::string path,
245
+ std::function<void(::React::JSValueArray)> callback) noexcept;
246
+
247
+ // df
248
+ REACT_METHOD(df)
249
+ winrt::fire_and_forget df(
250
+ std::function<void(::React::JSValueArray)> callback) noexcept;
251
+
252
+ REACT_METHOD(slice)
253
+ winrt::fire_and_forget slice(
254
+ std::string src,
255
+ std::string dest,
256
+ double start,
257
+ double end,
258
+ ::React::ReactPromise<std::string> promise) noexcept;
259
+
260
+ REACT_METHOD(mkdir)
261
+ void mkdir(std::string path, ::React::ReactPromise<bool>&& result) noexcept;
262
+
263
+ REACT_METHOD(readStream)
264
+ winrt::fire_and_forget readStream(std::string path, std::string encoding, double bufferSize, double tick, std::string streamId) noexcept;
265
+
266
+ REACT_METHOD(getEnvironmentDirs)
267
+ void getEnvironmentDirs(std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
268
+
269
+ REACT_METHOD(cancelRequest)
270
+ void cancelRequest(std::string taskId, std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
271
+
272
+ REACT_METHOD(enableProgressReport)
273
+ void enableProgressReport(std::string taskId, double interval, double count) noexcept;
274
+
275
+ REACT_METHOD(enableUploadProgressReport)
276
+ void enableUploadProgressReport(std::string taskId, double interval, double count) noexcept;
277
+
278
+ REACT_METHOD(presentOptionsMenu)
279
+ void presentOptionsMenu(std::string uri, std::string scheme, ::React::ReactPromise<::React::JSValueArray>&& result) noexcept;
280
+
281
+ REACT_METHOD(presentOpenInMenu)
282
+ void presentOpenInMenu(std::string uri, std::string scheme, ::React::ReactPromise<::React::JSValueArray>&& result) noexcept;
283
+
284
+ REACT_METHOD(presentPreview)
285
+ void presentPreview(std::string uri, std::string scheme, ::React::ReactPromise<::React::JSValueArray>&& result) noexcept;
286
+
287
+ REACT_METHOD(excludeFromBackupKey)
288
+ void excludeFromBackupKey(std::string url, ::React::ReactPromise<::React::JSValueArray>&& result) noexcept;
289
+
290
+ REACT_METHOD(emitExpiredEvent)
291
+ void emitExpiredEvent(std::function<void(std::string)> const& callback) noexcept;
292
+
293
+ REACT_METHOD(actionViewIntent)
294
+ void actionViewIntent(std::string path, std::string mime, std::string chooserTitle, ::React::ReactPromise<void>&& result) noexcept;
295
+
296
+ REACT_METHOD(addCompleteDownload)
297
+ void addCompleteDownload(::React::JSValue&& config, ::React::ReactPromise<void>&& result) noexcept;
298
+
299
+ REACT_METHOD(copyToInternal)
300
+ void copyToInternal(std::string contentUri, std::string destpath, ::React::ReactPromise<std::string>&& result) noexcept;
301
+
302
+ REACT_METHOD(copyToMediaStore)
303
+ void copyToMediaStore(::React::JSValue&& filedata, std::string mt, std::string path, ::React::ReactPromise<std::string>&& result) noexcept;
304
+
305
+ REACT_METHOD(createMediaFile)
306
+ void createMediaFile(::React::JSValue&& filedata, std::string mt, ::React::ReactPromise<std::string>&& result) noexcept;
307
+
308
+ REACT_METHOD(getBlob)
309
+ void getBlob(std::string contentUri, std::string encoding, ::React::ReactPromise<::React::JSValueArray>&& result) noexcept;
310
+
311
+ REACT_METHOD(getContentIntent)
312
+ void getContentIntent(std::string mime, ::React::ReactPromise<std::string>&& result) noexcept;
313
+
314
+ REACT_METHOD(getSDCardDir)
315
+ void getSDCardDir(::React::ReactPromise<std::string>&& result) noexcept;
316
+
317
+ REACT_METHOD(getSDCardApplicationDir)
318
+ void getSDCardApplicationDir(::React::ReactPromise<std::string>&& result) noexcept;
319
+
320
+ REACT_METHOD(scanFile)
321
+ void scanFile(::React::JSValueArray&& pairs, std::function<void(::React::JSValueArray const&)> const& callback) noexcept;
322
+
323
+ REACT_METHOD(writeToMediaFile)
324
+ void writeToMediaFile(std::string fileUri, std::string path, bool transformFile, ::React::ReactPromise<std::string>&& result) noexcept;
325
+
326
+ REACT_METHOD(addListener)
327
+ void addListener(std::string eventName) noexcept;
328
+
329
+ REACT_METHOD(removeListeners)
330
+ void removeListeners(double count) noexcept;
331
+
332
+ private:
333
+ React::ReactContext m_context;
334
+
335
+ constexpr static int64_t UNIX_EPOCH_IN_WINRT_SECONDS = 11644473600;
336
+
337
+ std::map<StreamId, ReactNativeBlobUtilStream> m_streamMap;
338
+ //winrt::Windows::Web::Http::HttpClient m_httpClient;
339
+ winrt::Microsoft::ReactNative::ReactContext m_reactContext;
340
+ TaskCancellationManager m_tasks;
341
+
342
+ winrt::Windows::Foundation::IAsyncAction ProcessRequestAsync(
343
+ const std::string& taskId,
344
+ const winrt::Windows::Web::Http::Filters::HttpBaseProtocolFilter& filter,
345
+ winrt::Windows::Web::Http::HttpRequestMessage& httpRequestMessage,
346
+ ReactNativeBlobUtilConfig& config,
347
+ std::function<void(std::string, std::string, std::string)> callback,
348
+ std::string& error) noexcept;
349
+
350
+ const std::map<std::string, std::function<CryptographyCore::HashAlgorithmProvider()>> availableHashes{
351
+ {"md5", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Md5()); } },
352
+ {"sha1", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha1()); } },
353
+ {"sha256", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha256()); } },
354
+ {"sha384", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha384()); } },
355
+ {"sha512", []() { return CryptographyCore::HashAlgorithmProvider::OpenAlgorithm(CryptographyCore::HashAlgorithmNames::Sha512()); } }
356
+ };
357
+
358
+ void splitPath(const std::string& fullPath,
359
+ winrt::hstring& directoryPath,
360
+ winrt::hstring& fileName) noexcept;
361
+
362
+ void splitPath(const std::wstring& fullPath,
363
+ winrt::hstring& directoryPath,
364
+ winrt::hstring& fileName) noexcept;
365
+
366
+ const std::string prefix{ "ReactNativeBlobUtil-file://" };
367
+
368
+ std::mutex m_mutex;
369
+ std::map<std::string, ReactNativeBlobUtilProgressConfig> downloadProgressMap;
370
+ std::map<std::string, ReactNativeBlobUtilProgressConfig> uploadProgressMap;
371
+ };
372
+
373
+ } // namespace winrt::ReactNativeBlobUtil