{"id":4551,"url":"https://github.com/itinance/react-native-fs","last_synced_at":"2025-05-12T13:24:42.293Z","repository":{"id":31725560,"uuid":"35291446","full_name":"itinance/react-native-fs","owner":"itinance","description":"Native filesystem access for react-native","archived":false,"fork":false,"pushed_at":"2024-03-18T00:17:22.000Z","size":4105,"stargazers_count":5017,"open_issues_count":623,"forks_count":1000,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-05-06T15:20:24.306Z","etag":null,"topics":["download","filesystem","react-native"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itinance.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-05-08T17:04:15.000Z","updated_at":"2025-05-03T11:36:12.000Z","dependencies_parsed_at":"2023-02-19T17:00:26.155Z","dependency_job_id":"517c6797-9e66-4646-98b3-7afcf0667ca7","html_url":"https://github.com/itinance/react-native-fs","commit_stats":{"total_commits":557,"total_committers":176,"mean_commits":3.164772727272727,"dds":0.8258527827648114,"last_synced_commit":"64aa755cc1d37f59fa205bf2d52dd71a7d691504"},"previous_names":["johanneslumpe/react-native-fs"],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Freact-native-fs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Freact-native-fs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Freact-native-fs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itinance%2Freact-native-fs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itinance","download_url":"https://codeload.github.com/itinance/react-native-fs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745891,"owners_count":21957461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["download","filesystem","react-native"],"created_at":"2024-01-05T20:17:16.022Z","updated_at":"2025-05-12T13:24:42.265Z","avatar_url":"https://github.com/itinance.png","language":"C++","readme":"# react-native-fs\n\nNative filesystem access for react-native\n\n## IMPORTANT\n\nFor RN \u003c 0.57 and/or Gradle \u003c 3 you MUST install react-native-fs at version @2.11.17!\n\nFor RN \u003e= 0.57 and/or Gradle \u003e= 3 you MUST install react-native-fs at version \u003e= @2.13.2!\n\nFor RN \u003e= 0.61 please install react-native-fs at version \u003e= @2.16.0!\n\n## Table of Contents\n1. [Changelog](#Changelog)\n1. Usage\n    1. [iOS](#usage-ios)\n    1. [Android](#usage-android)\n    1. [Windows](#usage-windows)\n1. [Examples](#Examples)\n1. [API](#API)\n1. [Background Downloads Tutorial (iOS)](#background-downloads-tutorial-ios)\n1. [Test / Demo App](#test--demo-app)\n\n## Changelog\n\nView the changelog [here](https://github.com/itinance/react-native-fs/blob/master/CHANGELOG.md).\n\n## Usage (iOS/macOS)\n\nFirst you need to install react-native-fs:\n\n```\nnpm install react-native-fs --save\n```\n\n**Note:** If your react-native version is \u003c 0.40 install with this tag instead:\n\n```\nnpm install react-native-fs@2.0.1-rc.2 --save\n```\n\nAs @a-koka pointed out, you should then update your package.json to\n`\"react-native-fs\": \"2.0.1-rc.2\"` (without the tilde)\n\n### Adding automatically with react-native link\n\nAt the command line, in your project folder, type:\n\n`react-native link react-native-fs`\n\nDone! No need to worry about manually adding the library to your project.\n\n###  Adding with CocoaPods\n\n Add the RNFS pod to your list of application pods in your Podfile, using the path from the Podfile to the installed module:~~\n\n```\npod 'RNFS', :path =\u003e '../node_modules/react-native-fs'\n```\n\nInstall pods as usual:\n```\npod install\n```\n\n### Adding Manually in XCode\n\nIn XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] Go to node_modules ➜ react-native-fs and add the .xcodeproj file\n\nIn XCode, in the project navigator, select your project. Add the `lib*.a` from the RNFS project to your project's Build Phases ➜ Link Binary With Libraries. Click the .xcodeproj file you added before in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both `$(SRCROOT)/../react-native/React` and `$(SRCROOT)/../../React` - mark both as recursive.\n\nRun your project (Cmd+R)\n\n## Usage (Android)\n\nAndroid support is currently limited to only the `DocumentDirectory`. This maps to the app's `files` directory.\n\nMake alterations to the following files:\n\n* `android/settings.gradle`\n\n```gradle\n...\ninclude ':react-native-fs'\nproject(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android')\n```\n\n* `android/app/build.gradle`\n\n```gradle\n...\ndependencies {\n    ...\n    implementation project(':react-native-fs')\n}\n```\n\n* register module (in MainActivity.java)\n\n  * For react-native below 0.19.0 (use `cat ./node_modules/react-native/package.json | grep version`)\n\n```java\nimport com.rnfs.RNFSPackage;  // \u003c--- import\n\npublic class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {\n\n  ......\n\n  @Override\n  protected void onCreate(Bundle savedInstanceState) {\n    super.onCreate(savedInstanceState);\n    mReactRootView = new ReactRootView(this);\n\n    mReactInstanceManager = ReactInstanceManager.builder()\n      .setApplication(getApplication())\n      .setBundleAssetName(\"index.android.bundle\")\n      .setJSMainModuleName(\"index.android\")\n      .addPackage(new MainReactPackage())\n      .addPackage(new RNFSPackage())      // \u003c------- add package\n      .setUseDeveloperSupport(BuildConfig.DEBUG)\n      .setInitialLifecycleState(LifecycleState.RESUMED)\n      .build();\n\n    mReactRootView.startReactApplication(mReactInstanceManager, \"ExampleRN\", null);\n\n    setContentView(mReactRootView);\n  }\n\n  ......\n\n}\n```\n\n  * For react-native 0.19.0 and higher\n```java\nimport com.rnfs.RNFSPackage; // \u003c------- add package\n\npublic class MainActivity extends ReactActivity {\n   // ...\n    @Override\n    protected List\u003cReactPackage\u003e getPackages() {\n      return Arrays.\u003cReactPackage\u003easList(\n        new MainReactPackage(), // \u003c---- add comma\n        new RNFSPackage() // \u003c---------- add package\n      );\n    }\n```\n\n  * For react-native 0.29.0 and higher ( in MainApplication.java )\n```java\nimport com.rnfs.RNFSPackage; // \u003c------- add package\n\npublic class MainApplication extends Application implements ReactApplication {\n   // ...\n    @Override\n    protected List\u003cReactPackage\u003e getPackages() {\n      return Arrays.\u003cReactPackage\u003easList(\n        new MainReactPackage(), // \u003c---- add comma\n        new RNFSPackage() // \u003c---------- add package\n      );\n    }\n```\n\n## Usage (Windows)\n\n### Adding automatically with react-native link\n\nThe `link` command also works for adding the native dependency on Windows:\n\n`react-native link react-native-fs`\n\n### Adding Manually in Visual Studio\n\nFollow the instructions in the ['Linking Libraries'](https://github.com/Microsoft/react-native-windows/blob/master/docs/LinkingLibrariesWindows.md) documentation on the react-native-windows GitHub repo. For the first step of adding the project to the Visual Studio solution file, the path to the project should be `../node_modules/react-native-fs/windows/RNFS/RNFS.csproj`.\n\n## Examples\n\n### Basic\n\n```javascript\n// require the module\nvar RNFS = require('react-native-fs');\n\n// get a list of files and directories in the main bundle\nRNFS.readDir(RNFS.MainBundlePath) // On Android, use \"RNFS.DocumentDirectoryPath\" (MainBundlePath is not defined)\n  .then((result) =\u003e {\n    console.log('GOT RESULT', result);\n\n    // stat the first file\n    return Promise.all([RNFS.stat(result[0].path), result[0].path]);\n  })\n  .then((statResult) =\u003e {\n    if (statResult[0].isFile()) {\n      // if we have a file, read it\n      return RNFS.readFile(statResult[1], 'utf8');\n    }\n\n    return 'no file';\n  })\n  .then((contents) =\u003e {\n    // log the file contents\n    console.log(contents);\n  })\n  .catch((err) =\u003e {\n    console.log(err.message, err.code);\n  });\n```\n\n### File creation\n\n```javascript\n// require the module\nvar RNFS = require('react-native-fs');\n\n// create a path you want to write to\n// :warning: on iOS, you cannot write into `RNFS.MainBundlePath`,\n// but `RNFS.DocumentDirectoryPath` exists on both platforms and is writable\nvar path = RNFS.DocumentDirectoryPath + '/test.txt';\n\n// write the file\nRNFS.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')\n  .then((success) =\u003e {\n    console.log('FILE WRITTEN!');\n  })\n  .catch((err) =\u003e {\n    console.log(err.message);\n  });\n\n```\n\n### File deletion\n```javascript\n// create a path you want to delete\nvar path = RNFS.DocumentDirectoryPath + '/test.txt';\n\nreturn RNFS.unlink(path)\n  .then(() =\u003e {\n    console.log('FILE DELETED');\n  })\n  // `unlink` will throw an error, if the item to unlink does not exist\n  .catch((err) =\u003e {\n    console.log(err.message);\n  });\n```\n\n### File upload (Android and IOS only)\n\n```javascript\n// require the module\nvar RNFS = require('react-native-fs');\n\nvar uploadUrl = 'http://requestb.in/XXXXXXX';  // For testing purposes, go to http://requestb.in/ and create your own link\n// create an array of objects of the files you want to upload\nvar files = [\n  {\n    name: 'test1',\n    filename: 'test1.w4a',\n    filepath: RNFS.DocumentDirectoryPath + '/test1.w4a',\n    filetype: 'audio/x-m4a'\n  }, {\n    name: 'test2',\n    filename: 'test2.w4a',\n    filepath: RNFS.DocumentDirectoryPath + '/test2.w4a',\n    filetype: 'audio/x-m4a'\n  }\n];\n\nvar upload\n= (response) =\u003e {\n  var jobId = response.jobId;\n  console.log('UPLOAD HAS BEGUN! JobId: ' + jobId);\n};\n\nvar uploadProgress = (response) =\u003e {\n  var percentage = Math.floor((response.totalBytesSent/response.totalBytesExpectedToSend) * 100);\n  console.log('UPLOAD IS ' + percentage + '% DONE!');\n};\n\n// upload files\nRNFS.uploadFiles({\n  toUrl: uploadUrl,\n  files: files,\n  method: 'POST',\n  headers: {\n    'Accept': 'application/json',\n  },\n  fields: {\n    'hello': 'world',\n  },\n  begin: uploadBegin,\n  progress: uploadProgress\n}).promise.then((response) =\u003e {\n    if (response.statusCode == 200) {\n      console.log('FILES UPLOADED!'); // response.statusCode, response.headers, response.body\n    } else {\n      console.log('SERVER ERROR');\n    }\n  })\n  .catch((err) =\u003e {\n    if(err.description === \"cancelled\") {\n      // cancelled by user\n    }\n    console.log(err);\n  });\n\n```\n\n## API\n\n### Constants\n\nThe following constants are available on the `RNFS` export:\n\n- `MainBundlePath` (`String`) The absolute path to the main bundle directory (not available on Android)\n- `CachesDirectoryPath` (`String`) The absolute path to the caches directory\n- `ExternalCachesDirectoryPath` (`String`) The absolute path to the external caches directory (android only)\n- `DocumentDirectoryPath`  (`String`) The absolute path to the document directory\n- `DownloadDirectoryPath` (`String`) The absolute path to the download directory (on android and Windows only)\n- `TemporaryDirectoryPath` (`String`) The absolute path to the temporary directory (falls back to Caching-Directory on Android)\n- `LibraryDirectoryPath` (`String`) The absolute path to the NSLibraryDirectory (iOS only)\n- `ExternalDirectoryPath` (`String`) The absolute path to the external files, shared directory (android only)\n- `ExternalStorageDirectoryPath` (`String`) The absolute path to the external storage, shared directory (android only)\n- `PicturesDirectoryPath` (`String`) The absolute path to the pictures directory (Windows only)\n- `RoamingDirectoryPath` (`String`) The absolute path to the roaming directory (Windows only)\n\n\nIMPORTANT: when using `ExternalStorageDirectoryPath` it's necessary to request permissions (on Android) to read and write on the external storage, here an example: [React Native Offical Doc](https://facebook.github.io/react-native/docs/permissionsandroid)\n\n### `readDir(dirpath: string): Promise\u003cReadDirItem[]\u003e`\n\nReads the contents of `path`. This must be an absolute path. Use the above path constants to form a usable file path.\n\nThe returned promise resolves with an array of objects with the following properties:\n\n```js\ntype ReadDirItem = {\n  ctime: date;     // The creation date of the file (iOS only)\n  mtime: date;     // The last modified date of the file\n  name: string;     // The name of the item\n  path: string;     // The absolute path to the item\n  size: string;     // Size in bytes\n  isFile: () =\u003e boolean;        // Is the item just a file?\n  isDirectory: () =\u003e boolean;   // Is the item a directory?\n};\n```\n\n### `readDirAssets(dirpath: string): Promise\u003cReadDirItem[]\u003e`\n\nReads the contents of `dirpath ` in the Android app's assets folder.\n`dirpath ` is the relative path to the file from the root of the `assets` folder.\n\nThe returned promise resolves with an array of objects with the following properties:\n\n```js\ntype ReadDirItem = {\n  name: string;     // The name of the item\n  path: string;     // The absolute path to the item\n  size: string;     // Size in bytes.\n  \t\t\t\t\t\t// Note that the size of files compressed during the creation of the APK (such as JSON files) cannot be determined.\n  \t\t\t\t\t\t// `size` will be set to -1 in this case.\n  isFile: () =\u003e boolean;        // Is the file just a file?\n  isDirectory: () =\u003e boolean;   // Is the file a directory?\n};\n```\n\nNote: Android only.\n\n### `readdir(dirpath: string): Promise\u003cstring[]\u003e`\n\nNode.js style version of `readDir` that returns only the names. Note the lowercase `d`.\n\n### `stat(filepath: string): Promise\u003cStatResult\u003e`\n\nStats an item at `filepath`. If the `filepath` is linked to a virtual file, for example Android Content URI, the `originalPath` can be used to find the pointed file path.\nThe promise resolves with an object with the following properties:\n\n```js\ntype StatResult = {\n  path:            // The same as filepath argument\n  ctime: date;     // The creation date of the file\n  mtime: date;     // The last modified date of the file\n  size: number;     // Size in bytes\n  mode: number;     // UNIX file mode\n  originalFilepath: string;    // ANDROID: In case of content uri this is the pointed file path, otherwise is the same as path\n  isFile: () =\u003e boolean;        // Is the file just a file?\n  isDirectory: () =\u003e boolean;   // Is the file a directory?\n};\n```\n\n### `readFile(filepath: string, encoding?: string): Promise\u003cstring\u003e`\n\nReads the file at `path` and return contents. `encoding` can be one of `utf8` (default), `ascii`, `base64`. Use `base64` for reading binary files.\n\nNote: you will take quite a performance hit if you are reading big files\n\n### `read(filepath: string, length = 0, position = 0, encodingOrOptions?: any): Promise\u003cstring\u003e`\n\nReads `length` bytes from the given `position` of the file at `path` and returns contents. `encoding` can be one of `utf8` (default), `ascii`, `base64`. Use `base64` for reading binary files.\n\nNote: reading big files piece by piece using this method may be useful in terms of performance.\n\n### `readFileAssets(filepath:string, encoding?: string): Promise\u003cstring\u003e`\n\nReads the file at `path` in the Android app's assets folder and return contents. `encoding` can be one of `utf8` (default), `ascii`, `base64`. Use `base64` for reading binary files.\n\n`filepath` is the relative path to the file from the root of the `assets` folder.\n\nNote: Android only.\n\n### `readFileRes(filename:string, encoding?: string): Promise\u003cstring\u003e`\n\nReads the file named `filename` in the Android app's `res` folder and return contents. Only the file name (not folder) needs to be specified. The file type will be detected from the extension and automatically located within `res/drawable` (for image files) or `res/raw` (for everything else). `encoding` can be one of `utf8` (default), `ascii`, `base64`. Use `base64` for reading binary files.\n\nNote: Android only.\n\n### `writeFile(filepath: string, contents: string, encoding?: string): Promise\u003cvoid\u003e`\n\nWrite the `contents` to `filepath`. `encoding` can be one of `utf8` (default), `ascii`, `base64`. `options` optionally takes an object specifying the file's properties, like mode etc.\n\n### `appendFile(filepath: string, contents: string, encoding?: string): Promise\u003cvoid\u003e`\n\nAppend the `contents` to `filepath`. `encoding` can be one of `utf8` (default), `ascii`, `base64`.\n\n### `write(filepath: string, contents: string, position?: number, encoding?: string): Promise\u003cvoid\u003e`\n\nWrite the `contents` to `filepath` at the given random access position. When `position` is `undefined` or `-1` the contents is appended to the end of the file. `encoding` can be one of `utf8` (default), `ascii`, `base64`.\n\n### `moveFile(filepath: string, destPath: string): Promise\u003cvoid\u003e`\n\nMoves the file located at `filepath` to `destPath`. This is more performant than reading and then re-writing the file data because the move is done natively and the data doesn't have to be copied or cross the bridge.\n\nNote: Overwrites existing file in Windows.\n\n### `copyFolder(srcFolderPath: string, destFolderPath: string): Promise\u003cvoid\u003e`\n\nCopies the contents located at `srcFolderPath` to `destFolderPath`.\n\nNote: Windows only. This method is recommended when directories need to be copied from one place to another.\n\n### `copyFile(filepath: string, destPath: string): Promise\u003cvoid\u003e`\n\nCopies the file located at `filepath` to `destPath`.\n\nNote: On Android and Windows copyFile will overwrite `destPath` if it already exists. On iOS an error will be thrown if the file already exists.\n\n### `copyFileAssets(filepath: string, destPath: string): Promise\u003cvoid\u003e`\n\nCopies the file at `filepath` in the Android app's assets folder and copies it to the given `destPath ` path.\n\nNote: Android only. Will overwrite destPath if it already exists.\n\n### `copyFileRes(filename: string, destPath: string): Promise\u003cvoid\u003e`\n\nCopies the file named `filename` in the Android app's res folder and copies it to the given `destPath ` path. `res/drawable` is used as the source parent folder for image files, `res/raw` for everything else.\n\nNote: Android only. Will overwrite destPath if it already exists.\n\n### (iOS only) `copyAssetsFileIOS(imageUri: string, destPath: string, width: number, height: number, scale?: number, compression?: number, resizeMode?: string): Promise\u003cstring\u003e`\n\n*Not available on Mac Catalyst.*\n\nReads an image file from Camera Roll and writes to `destPath`. This method [assumes the image file to be JPEG file](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L752-L753). This method will download the original from iCloud if necessary.\n\n#### Parameters\n\n##### `imageUri` string (required)\n\nURI of a file in Camera Roll. Can be [either of the following formats](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L781-L785):\n\n- `ph://CC95F08C-88C3-4012-9D6D-64A413D254B3/L0/001`\n- `assets-library://asset/asset.JPG?id=CC95F08C-88C3-4012-9D6D-64A413D254B3\u0026ext=JPG`\n\n##### `destPath` string (required)\n\nDestination to which the copied file will be saved, e.g. `RNFS.TemporaryDirectoryPath + 'example.jpg'`.\n\n##### `width` number (required)\n\nCopied file's image width will be resized to `width`. [If 0 is provided, width won't be resized.](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L808)\n\n##### `height` number (required)\n\nCopied file's image height will be resized to `height`. [If 0 is provided, height won't be resized.](https://github.com/itinance/react-native-fs/blob/f2f8f4a058cd9acfbcac3b8cf1e08fa1e9b09786/RNFSManager.m#L808)\n\n##### `scale` number (optional)\n\nCopied file's image will be scaled proportional to `scale` factor from `width` x `height`. If both `width` and `height` are 0, the image won't scale. Range is [0.0, 1.0] and default is 1.0.\n\n##### `compression` number (optional)\n\nQuality of copied file's image. The value 0.0 represents the maximum compression (or lowest quality) while the value 1.0 represents the least compression (or best quality). Range is [0.0, 1.0] and default is 1.0.\n\n##### `resizeMode` string (optional)\n\nIf `resizeMode` is 'contain', copied file's image will be scaled so that its larger dimension fits `width` x `height`. If `resizeMode` is other value than 'contain', the image will be scaled so that it completely fills `width` x `height`. Default is 'contain'. Refer to [PHImageContentMode](https://developer.apple.com/documentation/photokit/phimagecontentmode).\n\n#### Return value\n\n##### `Promise\u003cstring\u003e`\n\nCopied file's URI.\n\n#### Video-Support\n\nOne can use this method also to create a thumbNail from a video in a specific size.\nCurrently it is impossible to specify a concrete position, the OS will decide wich\nThumbnail you'll get then.\nTo copy a video from assets-library and save it as a mp4-file, refer to copyAssetsVideoIOS.\n\nFurther information: https://developer.apple.com/reference/photos/phimagemanager/1616964-requestimageforasset\nThe promise will on success return the final destination of the file, as it was defined in the destPath-parameter.\n\n### (iOS only) `copyAssetsVideoIOS(videoUri: string, destPath: string): Promise\u003cstring\u003e`\n\n*Not available on Mac Catalyst.*\n\nCopies a video from assets-library, that is prefixed with 'assets-library://asset/asset.MOV?...' to a specific destination.\n\n### `unlink(filepath: string): Promise\u003cvoid\u003e`\n\nUnlinks the item at `filepath`. If the item does not exist, an error will be thrown.\n\nAlso recursively deletes directories (works like Linux `rm -rf`).\n\n### `exists(filepath: string): Promise\u003cboolean\u003e`\n\nCheck if the item exists at `filepath`. If the item does not exist, return false.\n\n### `existsAssets(filepath: string): Promise\u003cboolean\u003e`\n\nCheck in the Android assets folder if the item exists. `filepath` is the relative path from the root of the assets folder. If the item does not exist, return false.\n\nNote: Android only.\n\n### `existsRes(filename: string): Promise\u003cboolean\u003e`\n\nCheck in the Android res folder if the item named `filename` exists. `res/drawable` is used as the parent folder for image files, `res/raw` for everything else. If the item does not exist, return false.\n\nNote: Android only.\n\n### `hash(filepath: string, algorithm: string): Promise\u003cstring\u003e`\n\nReads the file at `path` and returns its checksum as determined by `algorithm`, which can be one of `md5`, `sha1`, `sha224`, `sha256`, `sha384`, `sha512`.\n\n### `touch(filepath: string, mtime?: Date, ctime?: Date): Promise\u003cstring\u003e`\n\nSets the modification timestamp `mtime` and creation timestamp `ctime` of the file at `filepath`. Setting `ctime` is supported on iOS and Windows, android always sets both timestamps to `mtime`.\n\n### `mkdir(filepath: string, options?: MkdirOptions): Promise\u003cvoid\u003e`\n\n```\ntype MkdirOptions = {\n  NSURLIsExcludedFromBackupKey?: boolean; // iOS only\n};\n```\n\nCreate a directory at `filepath`. Automatically creates parents and does not throw if already exists (works like Linux `mkdir -p`).\n\n(IOS only): The `NSURLIsExcludedFromBackupKey` property can be provided to set this attribute on iOS platforms. Apple will *reject* apps for storing offline cache data that does not have this attribute.\n\n### `downloadFile(options: DownloadFileOptions): { jobId: number, promise: Promise\u003cDownloadResult\u003e }`\n\n```js\ntype DownloadFileOptions = {\n  fromUrl: string;          // URL to download file from\n  toFile: string;           // Local filesystem path to save the file to\n  headers?: Headers;        // An object of headers to be passed to the server\n  background?: boolean;     // Continue the download in the background after the app terminates (iOS only)\n  discretionary?: boolean;  // Allow the OS to control the timing and speed of the download to improve perceived performance  (iOS only)\n  cacheable?: boolean;      // Whether the download can be stored in the shared NSURLCache (iOS only, defaults to true)\n  progressInterval?: number;\n  progressDivider?: number;\n  begin?: (res: DownloadBeginCallbackResult) =\u003e void; // Note: it is required when progress prop provided\n  progress?: (res: DownloadProgressCallbackResult) =\u003e void;\n  resumable?: () =\u003e void;    // only supported on iOS yet\n  connectionTimeout?: number // only supported on Android yet\n  readTimeout?: number       // supported on Android and iOS\n  backgroundTimeout?: number // Maximum time (in milliseconds) to download an entire resource (iOS only, useful for timing out background downloads)\n};\n```\n```js\ntype DownloadResult = {\n  jobId: number;          // The download job ID, required if one wishes to cancel the download. See `stopDownload`.\n  statusCode: number;     // The HTTP status code\n  bytesWritten: number;   // The number of bytes written to the file\n};\n```\n\nDownload file from `options.fromUrl` to `options.toFile`. Will overwrite any previously existing file.\n\nIf `options.begin` is provided, it will be invoked once upon download starting when headers have been received and passed a single argument with the following properties:\n\n```js\ntype DownloadBeginCallbackResult = {\n  jobId: number;          // The download job ID, required if one wishes to cancel the download. See `stopDownload`.\n  statusCode: number;     // The HTTP status code\n  contentLength: number;  // The total size in bytes of the download resource\n  headers: Headers;       // The HTTP response headers from the server\n};\n```\n\nIf `options.progress` is provided, it will be invoked continuously and passed a single argument with the following properties:\n\n```js\ntype DownloadProgressCallbackResult = {\n  jobId: number;          // The download job ID, required if one wishes to cancel the download. See `stopDownload`.\n  contentLength: number;  // The total size in bytes of the download resource\n  bytesWritten: number;   // The number of bytes written to the file so far\n};\n```\n\nIf `options.progressInterval` is provided, it will return progress events in the maximum frequency of `progressDivider`.\nFor example, if `progressInterval` = 100, you will not receive callbacks more often than every 100th millisecond.\n\nIf `options.progressDivider` is provided, it will return progress events that divided by `progressDivider`.\n\nFor example, if `progressDivider` = 10, you will receive only ten callbacks for this values of progress: 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100\nUse it for performance issues.\nIf `progressDivider` = 0, you will receive all `progressCallback` calls, default value is 0.\n\n(IOS only): `options.background` (`Boolean`) - Whether to continue downloads when the app is not focused (default: `false`)\n                           This option is currently only available for iOS, see the [Background Downloads Tutorial (iOS)](#background-downloads-tutorial-ios) section.\n\n(IOS only): If `options.resumable` is provided, it will be invoked when the download has stopped and and can be resumed using `resumeDownload()`.\n\n### `stopDownload(jobId: number): void`\n\nAbort the current download job with this ID. The partial file will remain on the filesystem.\n\n### (iOS only) `resumeDownload(jobId: number): void`\n\nResume the current download job with this ID.\n\n### (iOS only) `isResumable(jobId: number): Promise\u003cbool\u003e`\n\nCheck if the the download job with this ID is resumable with `resumeDownload()`.\n\nExample:\n\n```js\nif (await RNFS.isResumable(jobId) {\n    RNFS.resumeDownload(jobId)\n}\n```\n\n### (iOS only) `completeHandlerIOS(jobId: number): void`\n\nFor use when using background downloads, tell iOS you are done handling a completed download.\n\nRead more about background downloads in the [Background Downloads Tutorial (iOS)](#background-downloads-tutorial-ios) section.\n\n### `uploadFiles(options: UploadFileOptions): { jobId: number, promise: Promise\u003cUploadResult\u003e }`\n\n`options` (`Object`) - An object containing named parameters\n\n```js\ntype UploadFileOptions = {\n  toUrl: string;            // URL to upload file to\n  binaryStreamOnly?: boolean// Allow for binary data stream for file to be uploaded without extra headers, Default is 'false'\n  files: UploadFileItem[];  // An array of objects with the file information to be uploaded.\n  headers?: Headers;        // An object of headers to be passed to the server\n  fields?: Fields;          // An object of fields to be passed to the server\n  method?: string;          // Default is 'POST', supports 'POST' and 'PUT'\n  begin?: (res: UploadBeginCallbackResult) =\u003e void;\n  progress?: (res: UploadProgressCallbackResult) =\u003e void;\n};\n\n```\n```js\ntype UploadResult = {\n  jobId: number;        // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.\n  statusCode: number;   // The HTTP status code\n  headers: Headers;     // The HTTP response headers from the server\n  body: string;         // The HTTP response body\n};\n```\n\nEach file should have the following structure:\n\n```js\ntype UploadFileItem = {\n  name: string;       // Name of the file, if not defined then filename is used\n  filename: string;   // Name of file\n  filepath: string;   // Path to file\n  filetype: string;   // The mimetype of the file to be uploaded, if not defined it will get mimetype from `filepath` extension\n};\n```\n\nIf `options.begin` is provided, it will be invoked once upon upload has begun:\n\n```js\ntype UploadBeginCallbackResult = {\n  jobId: number;        // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.\n};\n```\n\nIf `options.progress` is provided, it will be invoked continuously and passed a single object with the following properties:\n\n```js\ntype UploadProgressCallbackResult = {\n  jobId: number;                      // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`.\n  totalBytesExpectedToSend: number;   // The total number of bytes that will be sent to the server\n  totalBytesSent: number;             // The number of bytes sent to the server\n};\n```\n\nPercentage can be computed easily by dividing `totalBytesSent` by `totalBytesExpectedToSend`.\n\n### (iOS only) `stopUpload(jobId: number): Promise\u003cvoid\u003e`\n\nAbort the current upload job with this ID.\n\n### `getFSInfo(): Promise\u003cFSInfoResult\u003e`\n\nReturns an object with the following properties:\n\n```js\ntype FSInfoResult = {\n  totalSpace: number;   // The total amount of storage space on the device (in bytes).\n  freeSpace: number;    // The amount of available storage space on the device (in bytes).\n};\n```\n\n### (Android only) `scanFile(path: string): Promise\u003cstring[]\u003e`\n\nScan the file using [Media Scanner](https://developer.android.com/reference/android/media/MediaScannerConnection).\n\n### (Android only) `getAllExternalFilesDirs(): Promise\u003cstring[]\u003e`\n\nReturns 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.\n\n### (iOS only) `pathForGroup(groupIdentifier: string): Promise\u003cstring\u003e`\n\n`groupIdentifier` (`string`) Any value from the *com.apple.security.application-groups* entitlements list.\n\nReturns the absolute path to the directory shared for all applications with the same security group identifier.\nThis directory can be used to to share files between application of the same developer.\n\nInvalid group identifier will cause a rejection.\n\nFor more information read the [Adding an App to an App Group](https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19) section.\n\n## Background Downloads Tutorial (iOS)\n\nBackground downloads in iOS require a bit of a setup.\n\nFirst, in your `AppDelegate.m` file add the following:\n\n```js\n#import \u003cRNFSManager.h\u003e\n\n...\n\n- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler\n{\n  [RNFSManager setCompletionHandlerForIdentifier:identifier completionHandler:completionHandler];\n}\n\n```\n\nThe `handleEventsForBackgroundURLSession` method is called when a background download is done and your app is not in the foreground.\n\nWe need to pass the `completionHandler` to RNFS along with its `identifier`.\n\nThe JavaScript will continue to work as usual when the download is done but now you must call `RNFS.completeHandlerIOS(jobId)` when you're done handling the download (show a notification etc.)\n\n**BE AWARE!** iOS will give about 30 sec. to run your code after `handleEventsForBackgroundURLSession` is called and until `completionHandler`\nis triggered so don't do anything that might take a long time (like unzipping), you will be able to do it after the user re-launces the app,\notherwide iOS will terminate your app.\n\n\n## Test / Demo app\n\nTest app to demostrate the use of the module. Useful for testing and developing the module:\n\nhttps://github.com/cjdell/react-native-fs-test\n","funding_links":[],"categories":["Components","\u003ca name=\"OS-\u0026-System-\u0026-File-Manager:-Native-Modules\"\u003eOS, System \u0026 File Manager: Native Modules\u003c/a\u003e","Saving generated code to gallery","C++","Libraries Used"],"sub_categories":["System"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinance%2Freact-native-fs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitinance%2Freact-native-fs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitinance%2Freact-native-fs/lists"}