react-native-filesystem
Simple file system access on iOS & Android.
All interaction is promise-based, and all content is written and read as UTF-8.
Setup
npm install react-native-filesystem --save
react-native link react-native-filesystem
This project is based on the 9-project-layout.
Usage
For a full list of available methods, see the API Reference.
Write to files
; { const fileContents = 'This is a my content.'; await FileSystem; console;}
Sub-directories are created automatically.
Read from files
{ const fileContents = await FileSystem; console;}
Delete files or folders
{ await FileSystem; console;}
Check if files or directories exist
{ const fileExists = await FileSystem; const directoryExists = await FileSystem; console; console;}
Selecting a storage class
All commands also take an optional last argument specifying a storage class. These classes roughly correspond to the four points of the iOS Data Storage Guidelines, and have similar behaviour on Android. Example usage:
FileSystem;
Files need to be read from the same storage class they're saved to, and two files can have the same name if they're located in different storages. The options are:
Storage class | Description |
---|---|
storage.backedUp |
These files are automatically backed up on supported devices |
storage.important |
Excluded from backup, but still kept around in low-storage situations |
storage.auxiliary |
Files that the app can function without. Can be deleted by the system in low-storage situations. |
storage.temporary |
For temporary files and caches. Can be deleted by the system any time. |
For full details, see the API Reference.
Questions?
Why yet another file system library?
I simply couldn't find one that satisfied my basic needs for simplicity.
Why not use the built-in AsyncStorage?
AsyncStorage is fine, but some times you want more control as to where the content is stored. This library lets you put it in backed-up folders, or play nice by marking content that can be deleted when the phone runs low on space.