Skip to content

Commit

Permalink
Merge pull request #490 from superandrew213/add-external-caches-dir
Browse files Browse the repository at this point in the history
Add ExternalCachesDirectoryPath
  • Loading branch information
itinance committed Jun 9, 2018
2 parents bf269a1 + bde2656 commit a38d2fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ var RNFS = {

MainBundlePath: RNFSManager.RNFSMainBundlePath,
CachesDirectoryPath: RNFSManager.RNFSCachesDirectoryPath,
ExternalCachesDirectoryPath: RNFSManager.RNFSExternalCachesDirectoryPath,
DocumentDirectoryPath: RNFSManager.RNFSDocumentDirectoryPath,
ExternalDirectoryPath: RNFSManager.RNFSExternalDirectoryPath,
ExternalStorageDirectoryPath: RNFSManager.RNFSExternalStorageDirectoryPath,
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ RNFS.readDir(RNFS.MainBundlePath) // On Android, use "RNFS.DocumentDirectoryPath
var RNFS = require('react-native-fs');

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

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

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

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

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.
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.

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

Expand Down
8 changes: 8 additions & 0 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class RNFSManager extends ReactContextBaseJavaModule {
private static final String RNFSPicturesDirectoryPath = "RNFSPicturesDirectoryPath";
private static final String RNFSTemporaryDirectoryPath = "RNFSTemporaryDirectoryPath";
private static final String RNFSCachesDirectoryPath = "RNFSCachesDirectoryPath";
private static final String RNFSExternalCachesDirectoryPath = "RNFSExternalCachesDirectoryPath";
private static final String RNFSDocumentDirectory = "RNFSDocumentDirectory";

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

File externalCachesDirectory = this.getReactApplicationContext().getExternalCacheDir();
if (externalCachesDirectory != null) {
constants.put(RNFSExternalCachesDirectoryPath, externalCachesDirectory.getAbsolutePath());
} else {
constants.put(RNFSExternalCachesDirectoryPath, null);
}

return constants;
}
}

0 comments on commit a38d2fa

Please sign in to comment.