0.1.0 • Published 7 years ago

react-native-filesystem v0.1.0

Weekly downloads
25
License
Apache-2.0
Repository
github
Last release
7 years ago

react-native-filesystem npm version

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

import FileSystem from 'react-native-filesystem';

async function writeToFile() {
  const fileContents = 'This is a my content.';
  await FileSystem.writeToFile('my-directory/my-file.txt', fileContents);
  console.log('file is written');
}

Sub-directories are created automatically.

Read from files

async function readFile() {
  const fileContents = await FileSystem.readFile('my-directory/my-file.txt');
  console.log(`read from file: ${fileContents}`);
}

Delete files or folders

async function deleteFile() {
  await FileSystem.delete('my-directory/my-file.txt');
  console.log('file is deleted');
}

Check if files or directories exist

async function checkIfFileExists() {
  const fileExists = await FileSystem.fileExists('my-directory/my-file.txt');
  const directoryExists = await FileSystem.directoryExists('my-directory/my-file.txt');
  console.log(`file exists: ${fileExists}`);
  console.log(`directory exists: ${directoryExists}`);
}

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.writeToFile('my-file.txt', 'My content', FileSystem.storage.important);

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 classDescription
storage.backedUpThese files are automatically backed up on supported devices
storage.importantExcluded from backup, but still kept around in low-storage situations
storage.auxiliaryFiles that the app can function without. Can be deleted by the system in low-storage situations.
storage.temporaryFor 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.

0.1.0

7 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago