Skip to content

Commit a38d2fa

Browse files
authored
Merge pull request #490 from superandrew213/add-external-caches-dir
Add ExternalCachesDirectoryPath
2 parents bf269a1 + bde2656 commit a38d2fa

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

FS.common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ var RNFS = {
560560

561561
MainBundlePath: RNFSManager.RNFSMainBundlePath,
562562
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
563+
ExternalCachesDirectoryPath: RNFSManager.RNFSExternalCachesDirectoryPath,
563564
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
564565
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
565566
ExternalStorageDirectoryPath: RNFSManager.RNFSExternalStorageDirectoryPath,

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath
228228
var RNFS = require('react-native-fs');
229229

230230
// create a path you want to write to
231-
// :warning: on iOS, you cannot write into `RNFS.MainBundlePath`,
231+
// :warning: on iOS, you cannot write into `RNFS.MainBundlePath`,
232232
// but `RNFS.DocumentDirectoryPath` exists on both platforms and is writable
233233
var path = RNFS.DocumentDirectoryPath + '/test.txt';
234234

@@ -327,6 +327,7 @@ The following constants are available on the `RNFS` export:
327327

328328
- `MainBundlePath` (`String`) The absolute path to the main bundle directory (not available on Android)
329329
- `CachesDirectoryPath` (`String`) The absolute path to the caches directory
330+
- `ExternalCachesDirectoryPath` (`String`) The absolute path to the external caches directory (android only)
330331
- `DocumentDirectoryPath` (`String`) The absolute path to the document directory
331332
- `TemporaryDirectoryPath` (`String`) The absolute path to the temporary directory (falls back to Caching-Directory on Android)
332333
- `LibraryDirectoryPath` (`String`) The absolute path to the NSLibraryDirectory (iOS only)
@@ -658,7 +659,7 @@ type FSInfoResult = {
658659

659660
### (Android only) `getAllExternalFilesDirs(): Promise<string[]>`
660661

661-
Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.
662+
Returns an array with the absolute paths to application-specific directories on all shared/external storage devices where the application can place persistent files it owns.
662663

663664
### (iOS only) `pathForGroup(groupIdentifier: string): Promise<string>`
664665

android/src/main/java/com/rnfs/RNFSManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class RNFSManager extends ReactContextBaseJavaModule {
4545
private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath";
4646
private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath";
4747
private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath";
48+
private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath";
4849
private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory";
4950

5051
private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
@@ -864,6 +865,13 @@ public Map<String, Object> getConstants() {
864865
constants.put(RNFSExternalDirectoryPath, null);
865866
}
866867

868+
File externalCachesDirectory = this.getReactApplicationContext().getExternalCacheDir();
869+
if (externalCachesDirectory != null) {
870+
constants.put(RNFSExternalCachesDirectoryPath, externalCachesDirectory.getAbsolutePath());
871+
} else {
872+
constants.put(RNFSExternalCachesDirectoryPath, null);
873+
}
874+
867875
return constants;
868876
}
869877
}

0 commit comments

Comments
 (0)