Skip to content

Commit 80a0f36

Browse files
author
Preben Ludviksen
committed
Changed directory locations to something more specific, to avoid conflicts with other directories.
1 parent 74dd08c commit 80a0f36

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# react-native-filesystem [![npm version](https://img.shields.io/npm/v/react-native-filesystem.svg?style=flat)](https://www.npmjs.com/package/react-native-filesystem)
2-
Simple file system API for iOS & Android, for dealing with text-files.
2+
Simple file system access on iOS & Android.
33

44
All interaction is promise-based, and all content is
55
written and read as UTF-8.
@@ -8,6 +8,8 @@ written and read as UTF-8.
88

99
npm install react-native-filesystem --save
1010
react-native link react-native-filesystem
11+
12+
This project is based on the [9-project-layout](https://github.com/benwixen/9-project-layout).
1113

1214
## Usage
1315

android/src/main/java/com/benwixen/rnfilesystem/RNFileSystem.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public String getName() {
4545
private String baseDirForStorage(Storage storage) {
4646
switch (storage) {
4747
case BACKED_UP:
48-
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/BackedUp";
48+
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/RNFS-BackedUp";
4949
case IMPORTANT:
50-
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/Important";
50+
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/RNFS-Important";
5151
case AUXILIARY:
52-
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/Auxiliary";
52+
return getReactApplicationContext().getFilesDir().getAbsolutePath() + "/RNFS-Auxiliary";
5353
case TEMPORARY:
54-
return getReactApplicationContext().getCacheDir().getAbsolutePath();
54+
return getReactApplicationContext().getCacheDir().getAbsolutePath() + "/RNFS-Temporary";
5555
default:
5656
throw new RuntimeException("Unrecognized storage: " + storage.toString());
5757
}

docs/reference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ supported iOS versions (8.0+) and
6666
[Auto Backup for Apps](https://developer.android.com/guide/topics/data/autobackup.html) on Android
6767
devices running Marshmallow or newer (6.0+). This is where you'd want to put user generated content.
6868

69-
Corresponds to `<Application_Home>/Documents` on iOS and a subdirectory of
69+
Corresponds to a subdirectory of `<Application_Home>/Documents` on iOS and
7070
[Context.getFilesDir()](https://developer.android.com/reference/android/content/Context.html#getFilesDir())
7171
on Android.
7272

@@ -87,7 +87,7 @@ On Android this storage behaves the same as `storage.important`.
8787

8888
This is for files that can be re-created, and that the app can live without. On iOS the system can
8989
delete these files in low storage situations. To play it safe, you should gracefully handle the
90-
case where they are gone, by checking for their existence.
90+
case where they are gone, by checking for their existence on application startup.
9191

9292
Corresponds to a subdirectory of `<Application_Home>/Library/Caches` on iOS, and a subdirectory of
9393
[Context.getFilesDir()](https://developer.android.com/reference/android/content/Context.html#getFilesDir())
@@ -109,6 +109,6 @@ To quote Apple's
109109
For temporary caches and data. The system can get rid of these at any time, but you are
110110
still required to delete them manually to free up space when they are no longer in use.
111111

112-
Corresponds to `<Application_Home>/tmp` on iOS and
112+
Corresponds to a subdirectory of `<Application_Home>/tmp` on iOS and
113113
[Context.getCacheDir()](https://developer.android.com/reference/android/content/Context.html#getCacheDir())
114114
on Android.

ios/RNFileSystem/RNFileSystem.m

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ @implementation RNFileSystem
1818
+ (NSURL*)baseDirForStorage:(NSString*)storage {
1919
NSFileManager *fileManager = [NSFileManager defaultManager];
2020
if ([storage isEqual:STORAGE_BACKED_UP]) {
21-
return [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
21+
NSURL *docsDir = [fileManager URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
22+
return [docsDir URLByAppendingPathComponent:@"RNFS-BackedUp"];
2223
} else if ([storage isEqual:STORAGE_IMPORTANT]) {
2324
NSURL *cachesDir = [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
24-
return [cachesDir URLByAppendingPathComponent:@"Important"];
25+
return [cachesDir URLByAppendingPathComponent:@"RNFS-Important"];
2526
} else if ([storage isEqual:STORAGE_AUXILIARY]) {
2627
NSURL *cachesDir = [fileManager URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
27-
return [cachesDir URLByAppendingPathComponent:@"Auxiliary"];
28+
return [cachesDir URLByAppendingPathComponent:@"RNFS-Auxiliary"];
2829
} else if ([storage isEqual:STORAGE_TEMPORARY]) {
29-
return [NSURL fileURLWithPath:NSTemporaryDirectory()];
30+
NSURL *tempDir = [NSURL fileURLWithPath:NSTemporaryDirectory()];
31+
return [tempDir URLByAppendingPathComponent:@"RNFS-Temporary"];
3032
} else {
3133
[NSException raise:@"InvalidArgument" format:[NSString stringWithFormat:@"Storage type not recognized: %@", storage]];
3234
return nil;

0 commit comments

Comments
 (0)