Skip to content

Commit e854048

Browse files
committed
Added directory access
1 parent 3eb1015 commit e854048

File tree

5 files changed

+62
-48
lines changed

5 files changed

+62
-48
lines changed

RNFetchBlobWin/App.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
ReloadInstructions,
2525
} from 'react-native/Libraries/NewAppScreen';
2626

27+
import RNFetchBlob from 'rn-fetch-blob';
28+
2729
const App: () => React$Node = () => {
2830
return (
2931
<>

RNFetchBlobWin/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dependencies": {
1313
"react": "16.13.1",
1414
"react-native": "0.63.2",
15-
"react-native-windows": "^0.63.0-0"
15+
"react-native-windows": "^0.63.0-0",
16+
"rn-fetch-blob": "https://github.com/avmoroz/rn-fetch-blob.git#dev"
1617
},
1718
"devDependencies": {
1819
"@babel/core": "^7.8.4",
@@ -27,4 +28,4 @@
2728
"jest": {
2829
"preset": "react-native"
2930
}
30-
}
31+
}

RNFetchBlobWin/windows/RNFetchBlobWin/RNFetchBlob.cpp

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,26 @@ void RNFetchBlob::Initialize(winrt::Microsoft::ReactNative::ReactContext const&
2828
//
2929
void RNFetchBlob::ConstantsViaConstantsProvider(winrt::Microsoft::ReactNative::ReactConstantProvider& constants) noexcept
3030
{
31-
// RNFS.MainBundlePath
32-
//constants.Add(L"RNFSMainBundlePath", to_string(Package::Current().InstalledLocation().Path()));
33-
34-
// RNFS.CachesDirectoryPath
35-
//constants.Add(L"RNFSCachesDirectoryPath", to_string(ApplicationData::Current().LocalCacheFolder().Path()));
36-
37-
// RNFS.ExternalCachesDirectoryPath - NULL in iOS (No equivalent in Windows)
38-
39-
// RNFS.DocumentDirectoryPath
40-
//constants.Add(L"RNFSDocumentDirectoryPath", to_string(ApplicationData::Current().LocalFolder().Path()));
41-
42-
// RNFS.DownloadDirectoryPath - IMPLEMENT for convenience? (absent in iOS and deprecated in Android)
43-
//constants.Add(L"RNFSDownloadDirectoryPath", UserDataPaths::GetDefault().Downloads());
44-
45-
// RNFS.ExternalDirectoryPath - NULL in iOS (Pending use case in Windows and deprecated in Android)
46-
//constants.Add(L"RNFSExternalDirectoryPath", UserDataPaths::GetDefault().Documents());
47-
48-
// RNFS.ExternalStorageDirectoryPath - NULL in iOS (Pending use case in Windows and deprecated in Android)
49-
50-
// RNFS.TemporaryDirectoryPath
51-
//constants.Add(L"RNFSTemporaryDirectoryPath", to_string(ApplicationData::Current().TemporaryFolder().Path()));
52-
53-
// RNFS.LibraryDirectoryPath - NULL in Android (No equivalent in Windows)
54-
55-
// RNFS.PicturesDirectoryPath - IMPLEMENT for convenience? (absent in iOS though and deprecated in Android)
56-
//constants.Add(L"RNFSPicturesDirectoryPath", UserDataPaths::GetDefault().Pictures());
57-
58-
// RNFS.FileProtectionKeys - NULL in Android (No equivalent in Windows)
59-
60-
// TODO: Check to see if these can be accessed after package created
61-
// Needed for synchronization across Windows devices
62-
///constants.Add(L"RNFSRoamingDirectoryPath", to_string(ApplicationData::Current().RoamingFolder().Path()));
63-
31+
// RNFetchBlob.DocumentDir
32+
constants.Add(L"DocumentDir", to_string(ApplicationData::Current().LocalFolder().Path()));
33+
34+
// RNFetchBlob.CacheDir
35+
constants.Add(L"CacheDir", to_string(ApplicationData::Current().LocalCacheFolder().Path()));
36+
37+
// RNFetchBlob.PictureDir
38+
constants.Add(L"PictureDir", UserDataPaths::GetDefault().Pictures());
39+
40+
// RNFetchBlob.MusicDir
41+
constants.Add(L"MusicDir", UserDataPaths::GetDefault().Music());
42+
43+
// RNFetchBlob.MovieDir
44+
constants.Add(L"MusicDir", UserDataPaths::GetDefault().Videos());
45+
46+
// RNFetchBlob.DownloadDirectoryPath - IMPLEMENT for convenience? (absent in iOS and deprecated in Android)
47+
constants.Add(L"DownloadDir", UserDataPaths::GetDefault().Downloads());
48+
49+
// RNFetchBlob.MainBundleDir
50+
constants.Add(L"MainBundleDir", to_string(Package::Current().InstalledLocation().Path()));
6451
}
6552

6653
// createFile
@@ -417,23 +404,28 @@ try
417404
}
418405
if (usedEncoding == EncodingOptions::BASE64)
419406
{
420-
std::wstring base64Content{ Cryptography::CryptographicBuffer::EncodeToBase64String(readBuffer) };
407+
// TODO: Investigate returning wstrings as parameters
408+
//std::wstring base64Content{ Cryptography::CryptographicBuffer::EncodeToBase64String(readBuffer) };
409+
std::string base64Content{ winrt::to_string(Cryptography::CryptographicBuffer::EncodeToBase64String(readBuffer)) };
421410
m_reactContext.CallJSFunction(L"RCTDeviceEventEmitter", L"emit", streamId,
422411
winrt::Microsoft::ReactNative::JSValueObject{
423-
{"data", base64Content},
412+
{"data", "base64Content"},
424413
});
425414
}
426415
else
427416
{
428-
std::wstring utf8Content{ Cryptography::CryptographicBuffer::ConvertBinaryToString(BinaryStringEncoding::Utf8, readBuffer) };
417+
// TODO: Investigate returning wstrings as parameters
418+
std::string utf8Content{ winrt::to_string(Cryptography::CryptographicBuffer::ConvertBinaryToString(BinaryStringEncoding::Utf8, readBuffer)) };
429419
if (usedEncoding == EncodingOptions::ASCII)
430420
{
431-
std::string asciiContent{ winrt::to_string(utf8Content) };
432-
std::wstring asciiResult{ winrt::to_hstring(asciiContent) };
421+
422+
//std::string asciiContent{ winrt::to_string(utf8Content) };
423+
std::string asciiContent{ utf8Content };
424+
//std::wstring asciiResult{ winrt::to_hstring(asciiContent) };
433425
// emit ascii content
434426
m_reactContext.CallJSFunction(L"RCTDeviceEventEmitter", L"emit", streamId,
435427
winrt::Microsoft::ReactNative::JSValueObject{
436-
{"data", asciiResult},
428+
{"data", asciiContent},
437429
});
438430
}
439431
else
@@ -456,7 +448,7 @@ catch (const hresult_error& ex)
456448
{
457449
m_reactContext.CallJSFunction(L"RCTDeviceEventEmitter", L"emit", L"DownloadBegin",
458450
winrt::Microsoft::ReactNative::JSValueObject{
459-
{streamId, L"help"},
451+
{streamId, winrt::to_string(ex.message()).c_str()},
460452
});
461453
}
462454

RNFetchBlobWin/windows/RNFetchBlobWin/RNFetchBlob.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,4 @@ struct RNFetchBlob
254254
void splitPath(const std::string& fullPath,
255255
winrt::hstring& directoryPath,
256256
winrt::hstring& fileName) noexcept;
257-
258-
//void splitPath(const winrt::hstring& fullPath,
259-
// winrt::hstring& directoryPath,
260-
// winrt::hstring& folderName) noexcept;
261-
262257
};

RNFetchBlobWin/yarn.lock

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,11 @@ balanced-match@^1.0.0:
17391739
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
17401740
integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c=
17411741

1742+
1743+
version "0.1.0"
1744+
resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb"
1745+
integrity sha1-eAqZyE59YAJgNhURxId2E78k9rs=
1746+
17421747
base64-js@^1.1.2, base64-js@^1.2.3:
17431748
version "1.3.1"
17441749
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.3.1.tgz#58ece8cb75dd07e71ed08c736abc5fac4dbf8df1"
@@ -3126,6 +3131,18 @@ glob-parent@^5.0.0:
31263131
dependencies:
31273132
is-glob "^4.0.1"
31283133

3134+
3135+
version "7.0.6"
3136+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
3137+
integrity sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=
3138+
dependencies:
3139+
fs.realpath "^1.0.0"
3140+
inflight "^1.0.4"
3141+
inherits "2"
3142+
minimatch "^3.0.2"
3143+
once "^1.3.0"
3144+
path-is-absolute "^1.0.0"
3145+
31293146
glob@^7.0.0, glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6:
31303147
version "7.1.6"
31313148
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
@@ -4879,7 +4896,7 @@ mimic-fn@^2.0.0, mimic-fn@^2.1.0:
48794896
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
48804897
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==
48814898

4882-
minimatch@^3.0.4:
4899+
minimatch@^3.0.2, minimatch@^3.0.4:
48834900
version "3.0.4"
48844901
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
48854902
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
@@ -5898,6 +5915,13 @@ rimraf@~2.2.6:
58985915
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.2.8.tgz#e439be2aaee327321952730f99a8929e4fc50582"
58995916
integrity sha1-5Dm+Kq7jJzIZUnMPmaiSnk/FBYI=
59005917

5918+
"rn-fetch-blob@https://github.com/avmoroz/rn-fetch-blob.git#dev":
5919+
version "0.12.0"
5920+
resolved "https://github.com/avmoroz/rn-fetch-blob.git#3eb10150536dcf9aa794bf365c6c75874e6c971d"
5921+
dependencies:
5922+
base-64 "0.1.0"
5923+
glob "7.0.6"
5924+
59015925
rsvp@^4.8.4:
59025926
version "4.8.5"
59035927
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-4.8.5.tgz#c8f155311d167f68f21e168df71ec5b083113734"

0 commit comments

Comments
 (0)