-
Notifications
You must be signed in to change notification settings - Fork 4
/
package.json
36 lines (36 loc) · 8.81 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"name": "react-native-file-manager",
"version": "1.0.1",
"description": "A file manger for react native",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://[email protected]/MiincGu/react-native-file-manager.git"
},
"keywords": [
"react-native"
],
"author": {
"name": "MiincGu"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/MiincGu/react-native-file-manager/issues"
},
"homepage": "https://github.com/MiincGu/react-native-file-manager#readme",
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^2.9.25",
"utf8": "^2.1.1"
},
"gitHead": "2714088d4daf0c72a7971c306dd01afcfacd1a27",
"readme": "## react-native-file-manager\n\nNative file system manager for react-native\n\n## Usage (iOS)\n\nFirst you need to install react-native-file-manager:\n\n```javascript\nnpm install react-native-file-manager --save\n```\n\nIn XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] Go to node_modules ➜ react-native-file-manager and add the .xcodeproj file\n\nIn XCode, in the project navigator, select your project. Add the lib*.a from the RNFileManager project to your project's Build Phases ➜ Link Binary With Libraries Click .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-file-manager'\nproject(':react-native-file-manager').projectDir = new File(settingsDir, '../node_modules/react-native-file-manager/android')\n```\n\n* `android/app/build.gradle`\n\n```gradle\n...\ndependencies {\n ...\n compile project(':react-native-file-manager')\n}\n```\n\n* register module (in MainActivity.java)\n\n```java\nimport com.rnfm.RNFileManagerPackage; // <--- 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 RNFileMangerPackage()) // <------- 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## Examples\n\n### Basic\n\n```javascript\n// require the module\nvar RNFileManager = require('react-native-file-manager');\n\n// get a list of files and directories in the main bundle\nRNFileManager.readDir(RNFileManager.MainBundlePath)\n .then((result) => {\n console.log('GOT RESULT', result);\n\n // stat the first file\n return Promise.all([RNFileManager.stat(result[0].path), result[0].path]);\n })\n .then((statResult) => {\n if (statResult[0].isFile()) {\n // if we have a file, read it\n return RNFileManager.readFile(statResult[1], 'utf8');\n }\n\n return 'no file';\n })\n .then((contents) => {\n // log the file contents\n console.log(contents);\n })\n .catch((err) => {\n console.log(err.message, err.code);\n });\n```\n\n### File creation\n\n```javascript\n// require the module\nvar RNFileManager = require('react-native-file-manager');\n\n// create a path you want to write to\nvar path = RNFileManager.DocumentDirectoryPath + '/test.txt';\n\n// write the file\nRNFileManager.writeFile(path, 'Lorem ipsum dolor sit amet', 'utf8')\n .then((success) => {\n console.log('FILE WRITTEN!');\n })\n .catch((err) => {\n console.log(err.message);\n });\n\n```\n\n### File deletion\n```javascript\n// create a path you want to delete\nvar path = RNFileManager.DocumentDirectoryPath + '/test.txt';\n\nreturn RNFileManager.unlink(path)\n // spread is a method offered by bluebird to allow for more than a\n // single return value of a promise. If you use `then`, you will receive\n // the values inside of an array\n .spread((success, path) => {\n console.log('FILE DELETED', success, path);\n })\n // `unlink` will throw an error, if the item to unlink does not exist\n .catch((err) => {\n console.log(err.message);\n });\n```\n\n## API\n\n### Constants\n\nThe following constants are available on the `RNFileManager` export:\n\n`MainBundlePath` (`String`) The absolute path to the main bundle directory \n`CachesDirectoryPath` (`String`) The absolute path to the caches directory \n`DocumentDirectoryPath` (`String`) The absolute path to the document directory\n\n### `promise readDir(path)`\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`name` (`String`) - The name of the item \n`path` (`String`) - The absolute path to the item \n`size` (`Number`) - Size in bytes\n\n### `promise readdir(path)`\n\nNode.js style version of `readDir` that returns only the names. Note the lowercase `d`.\n\n### `promise stat(path)`\n\nStats an item at `path`. \nThe promise resolves with an object with the following properties:\n\n`ctime` (`Date`) - The creation date of the item \n`mtime` (`Date`) - The modification date of the item \n`size` (`Number`) - The size of the item in bytes \n`isFile` (`Function`) - Returns true when the item is a file \n`isDirectory` (`Function`) - Returns true when the item is a directory\n\n### `promise readFile(path [, encoding])`\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### `promise writeFile(filepath, contents [, encoding, options])`\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\nThe promise resolves with a boolean.\n\n### `promise unlink(filepath)`\n\nUnlinks the item at `filepath`. If the item does not exist, an error will be thrown.\n\nThe promise resolves with an array, which contains a boolean and the path that has been unlinked. Tip: use `spread` to receive the two arguments instead of a single array in your handler.\n\nAlso recursively deletes directories (works like Linux `rm -rf`).\n\n### `promise mkdir(filepath [, excludeFromBackup])`\n\nCreate a directory at `filepath`. Automatically creates parents and does not throw if already exists (works like Linux `mkdir -p`).\n\nIOS only: If `excludeFromBackup` is true, then `NSURLIsExcludedFromBackupKey` attribute will be set. Apple will *reject* apps for storing offline cache data that does not have this attribute.\n\n### `promise downloadFile(url, filepath [, beginCallback, progressCallback])`\n\nDownload file from `url` to `filepath`. Will overwrite any previously existing file.\n\nIf `beginCallback` 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`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` (`Map`) - The HTTP response headers from the server \n\nIf `progressCallback` is provided, it will be invoked continuously and passed a single argument with the following properties:\n\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\nPercentage can be computed easily by dividing `bytesWritten` by `contentLength`.\n\n### `promise stopDownload(jobId)`\n\nAbort the current download job with this ID. The partial file will remain on the filesystem.\n",
"readmeFilename": "README.md",
"_id": "[email protected]",
"_shasum": "25b4a4b389680b022812d636463d70e3a815f47f",
"_from": "miincgu/react-native-file-manager",
"_resolved": "git://github.com/miincgu/react-native-file-manager.git#2714088d4daf0c72a7971c306dd01afcfacd1a27"
}