Initial commit

This commit is contained in:
Johannes Lumpe 2015-05-08 20:05:37 +03:00
commit 1821893891
17 changed files with 853 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
workbench

79
.jshintrc Normal file
View File

@ -0,0 +1,79 @@
{
"-W093": true,
"asi": false,
"bitwise": true,
"boss": false,
"browser": false,
"camelcase": true,
"couch": false,
"curly": true,
"debug": false,
"devel": true,
"dojo": false,
"eqeqeq": true,
"eqnull": false,
"esnext": true,
"evil": false,
"expr": true,
"forin": false,
"freeze": true,
"funcscope": true,
"gcl": false,
"globalstrict": true,
"immed": false,
"indent": 2,
"iterator": false,
"jquery": false,
"lastsemic": false,
"latedef": false,
"laxbreak": true,
"laxcomma": false,
"loopfunc": false,
"maxcomplexity": false,
"maxdepth": false,
"maxerr": 50,
"maxlen": 80,
"maxparams": false,
"maxstatements": false,
"mootools": false,
"moz": false,
"multistr": false,
"newcap": true,
"noarg": true,
"node": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"nonstandard": false,
"notypeof": false,
"noyield": false,
"phantom": false,
"plusplus": false,
"predef": [
"jasmine",
"describe",
"beforeEach",
"it",
"jest",
"pit",
"expect",
"rootRequire"
],
"proto": false,
"prototypejs": false,
"quotmark": true,
"rhino": false,
"scripturl": false,
"shadow": false,
"smarttabs": false,
"strict": true,
"sub": false,
"supernew": false,
"trailing": true,
"undef": true,
"unused": true,
"validthis": false,
"worker": false,
"wsh": false,
"yui": false
}

11
FS.android.js Normal file
View File

@ -0,0 +1,11 @@
'use strict';
var warning = require('warning');
var FS = {
test: function() {
warning("Not yet implemented for Android.");
}
};
module.exports = FS;

58
FS.ios.js Normal file
View File

@ -0,0 +1,58 @@
'use strict';
var RNFSManager = require('NativeModules').RNFSManager;
var Promise = require('bluebird');
var base64 = require('base-64');
var _readDir = Promise.promisify(RNFSManager.readDir);
var _stat = Promise.promisify(RNFSManager.stat);
var _readFile = Promise.promisify(RNFSManager.readFile);
var convertError = (err) => {
var error = new Error(err.description);
error.code = err.code;
throw error;
};
var NSFileTypeRegular = RNFSManager.NSFileTypeRegular;
var NSFileTypeDirectory = RNFSManager.NSFileTypeDirectory;
var RNFS = {
readDir(path, rootDir) {
return _readDir(path, rootDir)
.catch(convertError);
},
stat(filepath) {
return _stat(filepath)
.then((result) => {
return {
'ctime': new Date(result.ctime*1000),
'mtime': new Date(result.mtime*1000),
'size': result.size,
isFile: () => result.type === NSFileTypeRegular,
isDirectory: () => result.type === NSFileTypeDirectory,
};
})
.catch(convertError);
},
readFile(filepath, shouldDecode) {
var p = _readFile(filepath);
if (shouldDecode !== false) {
p = p.then((data) => {
return base64.decode(data);
});
}
return p.catch(convertError);
},
MainBundle: RNFSManager.MainBundleDirectory,
CachesDirectory: RNFSManager.NSCachesDirectory,
DocumentDirectory: RNFSManager.NSDocumentDirectory
};
module.exports = RNFS;

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 Johannes Lumpe
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

13
NSArray+Map.h Normal file
View File

@ -0,0 +1,13 @@
//
// NSArray+Map.h
// RNFS
//
// taken from http://stackoverflow.com/questions/6127638/nsarray-equivalent-of-map
#import <Foundation/Foundation.h>
@interface NSArray (Map)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
@end

17
NSArray+Map.m Normal file
View File

@ -0,0 +1,17 @@
//
// NSArray+Map.m
// RNFS
#import "NSArray+Map.h"
@implementation NSArray (Map)
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[result addObject:block(obj, idx)];
}];
return result;
}
@end

83
README.md Normal file
View File

@ -0,0 +1,83 @@
## react-native-fs
Native filesystem access for react-native
Note: this project is under development and functionality will improve over time. Currently it provides only the bare minimum of functionality.
Renaming, copying, and creating files will follow soon.
## Usage
First you need to install react-native-fs:
```javascript
npm install react-native-fs --save
```
In XCode, in the project navigator, right click Libraries ➜ Add Files to [your project's name] Go to node_modules ➜ react-native-keyboardevents and add the .xcodeproj file
In 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 .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.
Run your project (Cmd+R)
## Examples
### Basic
```javascript
// require the module
var RNFS = require('react-native-fs');
// get a list of files and directories in the main bundle
RNFS.readDir('/', RNFS.MainBundle)
.then((result) => {
console.log('GOT RESULT', result);
// stat the first file
return Promise.all([RNFS.stat(result[0].path), result[0].path]);
})
.then((statResult) => {
if (statResult[0].isFile()) {
// if we have a file, read it
return RNFS.readFile(statResult[1]);
}
return 'no file';
})
.then((contents) => {
// log the file contents
console.log(contents);
})
.catch((err) => {
console.log(err.message, err.code);
});
```
## API
### `promise readDir(path, directory)`
Reads the contents of `path` in `directory`.
`path` is a string and `directory` is one of the following:
`RNFS.MainBundle`, `RNFS.CachesDirectory`, `RNFS.DocumentDirectory`
The returned promise resolves with an array of objects with the following properties:
`name` (`String`), The name of the item
`path` (`String`), The absolute path to the item
### `promise stat(path)`
Stats an item at `path`.
The promise resolves with an object with the following properties:
`ctime` (`Date`) - The creation date of the item
`mtime` (`Date`) - The modification date of the item
`size` (`Number`) - The size of the item in bytes
`isFile` (`Function`) - Returns true when the item is a file
`isDirectory` (`Function`) - Returns true when the item is a directory
### `promise readFile(path, shouldDecode)`
Reads the file at `path` and - by default - decodes the transferred base64 string. If `shouldDecode` is `false`, the base64 encoded string is returned
Note: you will take quite a performance hit if you are reading big files

View File

@ -0,0 +1,262 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objects = {
/* Begin PBXBuildFile section */
F1E59BDF1ADD662800ACA28A /* RNFSManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F1E59BDE1ADD662800ACA28A /* RNFSManager.m */; };
F1EB08BB1AFD0E6A008F8F2B /* NSArray+Map.m in Sources */ = {isa = PBXBuildFile; fileRef = F1EB08BA1AFD0E6A008F8F2B /* NSArray+Map.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
F12AFB991ADAF8F800E0535D /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
F12AFB9B1ADAF8F800E0535D /* libRNFS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFS.a; sourceTree = BUILT_PRODUCTS_DIR; };
F1E59BDD1ADD662800ACA28A /* RNFSManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNFSManager.h; sourceTree = "<group>"; };
F1E59BDE1ADD662800ACA28A /* RNFSManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFSManager.m; sourceTree = "<group>"; };
F1EB08B91AFD0E6A008F8F2B /* NSArray+Map.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+Map.h"; sourceTree = "<group>"; };
F1EB08BA1AFD0E6A008F8F2B /* NSArray+Map.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+Map.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
F12AFB981ADAF8F800E0535D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
F12AFB921ADAF8F800E0535D = {
isa = PBXGroup;
children = (
F1EB08B91AFD0E6A008F8F2B /* NSArray+Map.h */,
F1EB08BA1AFD0E6A008F8F2B /* NSArray+Map.m */,
F1E59BDD1ADD662800ACA28A /* RNFSManager.h */,
F1E59BDE1ADD662800ACA28A /* RNFSManager.m */,
F12AFB9C1ADAF8F800E0535D /* Products */,
);
sourceTree = "<group>";
};
F12AFB9C1ADAF8F800E0535D /* Products */ = {
isa = PBXGroup;
children = (
F12AFB9B1ADAF8F800E0535D /* libRNFS.a */,
);
name = Products;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
F12AFB9A1ADAF8F800E0535D /* RNFS */ = {
isa = PBXNativeTarget;
buildConfigurationList = F12AFBAF1ADAF8F800E0535D /* Build configuration list for PBXNativeTarget "RNFS" */;
buildPhases = (
F12AFB971ADAF8F800E0535D /* Sources */,
F12AFB981ADAF8F800E0535D /* Frameworks */,
F12AFB991ADAF8F800E0535D /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = RNFS;
productName = RNLocalNotification;
productReference = F12AFB9B1ADAF8F800E0535D /* libRNFS.a */;
productType = "com.apple.product-type.library.static";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
F12AFB931ADAF8F800E0535D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
ORGANIZATIONNAME = "Johannes Lumpe";
TargetAttributes = {
F12AFB9A1ADAF8F800E0535D = {
CreatedOnToolsVersion = 6.3;
};
};
};
buildConfigurationList = F12AFB961ADAF8F800E0535D /* Build configuration list for PBXProject "RNFS" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
);
mainGroup = F12AFB921ADAF8F800E0535D;
productRefGroup = F12AFB9C1ADAF8F800E0535D /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
F12AFB9A1ADAF8F800E0535D /* RNFS */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
F12AFB971ADAF8F800E0535D /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
F1E59BDF1ADD662800ACA28A /* RNFSManager.m in Sources */,
F1EB08BB1AFD0E6A008F8F2B /* NSArray+Map.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
F12AFBAD1ADAF8F800E0535D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
};
name = Debug;
};
F12AFBAE1ADAF8F800E0535D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
F12AFBB01ADAF8F800E0535D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/node_modules/react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Debug;
};
F12AFBB11ADAF8F800E0535D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
HEADER_SEARCH_PATHS = (
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../../React/**",
"$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/node_modules/react-native/React/**",
);
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
F12AFB961ADAF8F800E0535D /* Build configuration list for PBXProject "RNFS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F12AFBAD1ADAF8F800E0535D /* Debug */,
F12AFBAE1ADAF8F800E0535D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
F12AFBAF1ADAF8F800E0535D /* Build configuration list for PBXNativeTarget "RNFS" */ = {
isa = XCConfigurationList;
buildConfigurations = (
F12AFBB01ADAF8F800E0535D /* Debug */,
F12AFBB11ADAF8F800E0535D /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = F12AFB931ADAF8F800E0535D /* Project object */;
}

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:RNLocalNotification.xcodeproj">
</FileRef>
</Workspace>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDESourceControlProjectFavoriteDictionaryKey</key>
<false/>
<key>IDESourceControlProjectIdentifier</key>
<string>D7886F59-B62A-41B8-8825-9080D60A1419</string>
<key>IDESourceControlProjectName</key>
<string>RNFS</string>
<key>IDESourceControlProjectOriginsDictionary</key>
<dict>
<key>DBE4178F9C07984232B2B4DF265B9CB05D770D92</key>
<string>https://github.com/johanneslumpe/react-native-keyboardevents.git</string>
</dict>
<key>IDESourceControlProjectPath</key>
<string>RNFS.xcodeproj</string>
<key>IDESourceControlProjectRelativeInstallPathDictionary</key>
<dict>
<key>DBE4178F9C07984232B2B4DF265B9CB05D770D92</key>
<string>../..</string>
</dict>
<key>IDESourceControlProjectURL</key>
<string>https://github.com/johanneslumpe/react-native-keyboardevents.git</string>
<key>IDESourceControlProjectVersion</key>
<integer>111</integer>
<key>IDESourceControlProjectWCCIdentifier</key>
<string>DBE4178F9C07984232B2B4DF265B9CB05D770D92</string>
<key>IDESourceControlProjectWCConfigurations</key>
<array>
<dict>
<key>IDESourceControlRepositoryExtensionIdentifierKey</key>
<string>public.vcs.git</string>
<key>IDESourceControlWCCIdentifierKey</key>
<string>DBE4178F9C07984232B2B4DF265B9CB05D770D92</string>
<key>IDESourceControlWCCName</key>
<string>react-native-fs</string>
</dict>
</array>
</dict>
</plist>

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F12AFB9A1ADAF8F800E0535D"
BuildableName = "libRNFS.a"
BlueprintName = "RNFS"
ReferencedContainer = "container:RNFS.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F12AFB9A1ADAF8F800E0535D"
BuildableName = "libRNFS.a"
BlueprintName = "RNFS"
ReferencedContainer = "container:RNFS.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F12AFB9A1ADAF8F800E0535D"
BuildableName = "libRNFS.a"
BlueprintName = "RNFS"
ReferencedContainer = "container:RNFS.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F12AFB9A1ADAF8F800E0535D"
BuildableName = "libRNFS.a"
BlueprintName = "RNFS"
ReferencedContainer = "container:RNFS.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>RNKeyboardEvents.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>F12AFB9A1ADAF8F800E0535D</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>F12AFBA51ADAF8F800E0535D</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>

14
RNFSManager.h Normal file
View File

@ -0,0 +1,14 @@
//
// RNFSManager.h
// RNFSManager
//
// Created by Johannes Lumpe on 08/05/15.
// Copyright (c) 2015 Johannes Lumpe. All rights reserved.
//
#import "RCTBridgeModule.h"
#import "RCTLog.h"
@interface RNFSManager : NSObject <RCTBridgeModule>
@end

105
RNFSManager.m Normal file
View File

@ -0,0 +1,105 @@
//
// RNFSManager.m
// RNFSManager
//
// Created by Johannes Lumpe on 08/05/15.
// Copyright (c) 2015 Johannes Lumpe. All rights reserved.
//
#import "RNFSManager.h"
#import "RCTConvert.h"
#import "RCTBridge.h"
#import "NSArray+Map.h"
@implementation RNFSManager
static int MainBundleDirectory = 999;
@synthesize bridge = _bridge;
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(readDir:(NSString*)directory inFolder:(NSNumber*)folder callback:(RCTResponseSenderBlock)callback){
NSString *path;
int folderInt = [folder integerValue];
//NSLog(@"%d %d", folderInt, MainBundleDirectory);
if (folderInt == MainBundleDirectory) {
path = [[NSBundle mainBundle] bundlePath];
} else {
NSArray *paths = NSSearchPathForDirectoriesInDomains(folderInt, NSUserDomainMask, YES);
path = [paths objectAtIndex:0];
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString * dirPath = [path stringByAppendingPathComponent:directory];
NSArray *contents = [fileManager contentsOfDirectoryAtPath:dirPath error:&error];
contents = [contents mapObjectsUsingBlock:^id(id obj, NSUInteger idx) {
return @{
@"name": (NSString*)obj,
@"path": [dirPath stringByAppendingPathComponent:(NSString*)obj]
};
}];
if (error) {
return callback([self makeErrorPayload:error]);
}
callback(@[[NSNull null], contents]);
}
RCT_EXPORT_METHOD(stat:(NSString*)filepath callback:(RCTResponseSenderBlock)callback){
NSError *error;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:&error];
// NSLog(@"%@", attributes);
if (error) {
return callback([self makeErrorPayload:error]);
}
attributes = @{
@"ctime": [self dateToTimeIntervalNumber:(NSDate*)[attributes objectForKey:NSFileCreationDate]],
@"mtime": [self dateToTimeIntervalNumber:(NSDate*)[attributes objectForKey:NSFileModificationDate]],
@"size": [attributes objectForKey:NSFileSize],
@"type": [attributes objectForKey:NSFileType],
@"mode": [NSNumber numberWithInteger:[[NSString stringWithFormat:@"%o", [(NSNumber*)[attributes objectForKey:NSFilePosixPermissions] integerValue]] integerValue]]
};
callback(@[[NSNull null], attributes]);
}
RCT_EXPORT_METHOD(readFile:(NSString*)filepath callback:(RCTResponseSenderBlock)callback){
NSData *content = [[NSFileManager defaultManager] contentsAtPath:filepath];
NSString *base64Content = [content base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
NSLog(@"%@", base64Content);
if (!base64Content) {
return callback(@[[NSString stringWithFormat:@"Could not read file at path %@", filepath]]);
}
callback(@[[NSNull null], base64Content]);
}
- (NSNumber*) dateToTimeIntervalNumber:(NSDate*)date {
return [NSNumber numberWithDouble:[date timeIntervalSince1970]];
}
- (NSArray*) makeErrorPayload:(NSError*)error {
return @[@{
@"description": error.localizedDescription,
@"code": [NSNumber numberWithInteger:error.code]
}];
}
- (NSDictionary *)constantsToExport
{
return @{
@"NSCachesDirectory": [NSNumber numberWithInteger:NSCachesDirectory],
@"NSDocumentDirectory": [NSNumber numberWithInteger:NSDocumentDirectory],
@"MainBundleDirectory": [NSNumber numberWithInteger:MainBundleDirectory],
@"NSFileTypeRegular": NSFileTypeRegular,
@"NSFileTypeDirectory": NSFileTypeDirectory
};
}
@end

27
package.json Normal file
View File

@ -0,0 +1,27 @@
{
"name": "react-native-fs",
"version": "0.1.0",
"description": "Native filesystem access for react-native",
"main": "FS.ios.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@github.com:johanneslumpe/react-native-fs.git"
},
"keywords": [
"react-component",
"react-native",
"ios",
"fs",
"filesystem"
],
"author": "Johannes Lumpe <johannes@lum.pe> (https://github.com/johanneslumpe)",
"license": "MIT",
"dependencies": {
"base-64": "^0.1.0",
"bluebird": "^2.9.25",
"react-native": ">=0.3.4 <0.5.0"
}
}