add exist method
This commit is contained in:
parent
8ef4fa1f65
commit
dd320b3a5a
|
@ -15,6 +15,7 @@ var base64 = require('base-64');
|
||||||
var utf8 = require('utf8');
|
var utf8 = require('utf8');
|
||||||
|
|
||||||
var _readDir = Promise.promisify(RNFSManager.readDir);
|
var _readDir = Promise.promisify(RNFSManager.readDir);
|
||||||
|
var _exist = Promise.promisify(RNFSManager.exist);
|
||||||
var _stat = Promise.promisify(RNFSManager.stat);
|
var _stat = Promise.promisify(RNFSManager.stat);
|
||||||
var _readFile = Promise.promisify(RNFSManager.readFile);
|
var _readFile = Promise.promisify(RNFSManager.readFile);
|
||||||
var _writeFile = Promise.promisify(RNFSManager.writeFile);
|
var _writeFile = Promise.promisify(RNFSManager.writeFile);
|
||||||
|
@ -82,6 +83,11 @@ var RNFS = {
|
||||||
.catch(convertError);
|
.catch(convertError);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
exist(filepath) {
|
||||||
|
return _exist(filepath)
|
||||||
|
.catch(convertError);
|
||||||
|
},
|
||||||
|
|
||||||
readFile(filepath, encoding) {
|
readFile(filepath, encoding) {
|
||||||
if (!encoding) encoding = 'utf8';
|
if (!encoding) encoding = 'utf8';
|
||||||
|
|
||||||
|
|
|
@ -200,6 +200,12 @@ The promise resolves with an array, which contains a boolean and the path that h
|
||||||
|
|
||||||
Also recursively deletes directories (works like Linux `rm -rf`).
|
Also recursively deletes directories (works like Linux `rm -rf`).
|
||||||
|
|
||||||
|
### `promise exist(filepath)`
|
||||||
|
|
||||||
|
check if the item exist at `filepath`. If the item does not exist, return false.
|
||||||
|
|
||||||
|
The promise resolves with boolean.
|
||||||
|
|
||||||
### `promise mkdir(filepath [, excludeFromBackup])`
|
### `promise mkdir(filepath [, excludeFromBackup])`
|
||||||
|
|
||||||
Create a directory at `filepath`. Automatically creates parents and does not throw if already exists (works like Linux `mkdir -p`).
|
Create a directory at `filepath`. Automatically creates parents and does not throw if already exists (works like Linux `mkdir -p`).
|
||||||
|
|
|
@ -56,6 +56,14 @@ RCT_EXPORT_METHOD(readDir:(NSString *)dirPath
|
||||||
callback(@[[NSNull null], contents]);
|
callback(@[[NSNull null], contents]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(exist:(NSString *)filepath
|
||||||
|
callback:(RCTResponseSenderBlock)callback)
|
||||||
|
{
|
||||||
|
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:filepath];
|
||||||
|
|
||||||
|
callback(@[[NSNull null], [NSNumber numberWithBool:fileExists]]);
|
||||||
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(stat:(NSString *)filepath
|
RCT_EXPORT_METHOD(stat:(NSString *)filepath
|
||||||
callback:(RCTResponseSenderBlock)callback)
|
callback:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,6 +72,17 @@ public class RNFSManager extends ReactContextBaseJavaModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
public void exist(String filepath, Callback callback) {
|
||||||
|
try {
|
||||||
|
File file = new File(filepath);
|
||||||
|
callback.invoke(null, file.exists());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
callback.invoke(makeErrorPayload(ex));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ReactMethod
|
@ReactMethod
|
||||||
public void readFile(String filepath, Callback callback) {
|
public void readFile(String filepath, Callback callback) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue