Skip to content

Commit bde2656

Browse files
Add ExternalCachesDirectoryPath
1 parent 9b130ad commit bde2656

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
@@ -557,6 +557,7 @@ var RNFS = {
557557

558558
MainBundlePath: RNFSManager.RNFSMainBundlePath,
559559
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
560+
ExternalCachesDirectoryPath: RNFSManager.RNFSExternalCachesDirectoryPath,
560561
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
561562
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
562563
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)
@@ -656,7 +657,7 @@ type FSInfoResult = {
656657

657658
### (Android only) `getAllExternalFilesDirs(): Promise<string[]>`
658659

659-
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.
660+
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.
660661

661662
### (iOS only) `pathForGroup(groupIdentifier: string): Promise<string>`
662663

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class RNFSManager extends ReactContextBaseJavaModule {
4141
private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath";
4242
private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath";
4343
private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath";
44+
private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath";
4445
private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory";
4546

4647
private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
@@ -764,6 +765,13 @@ public Map<String, Object> getConstants() {
764765
constants.put(RNFSExternalDirectoryPath, null);
765766
}
766767

768+
File externalCachesDirectory = this.getReactApplicationContext().getExternalCacheDir();
769+
if (externalCachesDirectory != null) {
770+
constants.put(RNFSExternalCachesDirectoryPath, externalCachesDirectory.getAbsolutePath());
771+
} else {
772+
constants.put(RNFSExternalCachesDirectoryPath, null);
773+
}
774+
767775
return constants;
768776
}
769777
}

0 commit comments

Comments
 (0)