Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
Fix writeToFile method for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
hnq90 committed Jun 6, 2017
1 parent a1db685 commit 5e3d029
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
8 changes: 3 additions & 5 deletions ios/RNFileSystem/RNFileSystem.m
Expand Up @@ -39,7 +39,6 @@ + (void)createDirectoriesIfNeeded:(NSURL*)path {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *directory = [[path URLByDeletingLastPathComponent] path];
[fileManager createDirectoryAtPath:directory withIntermediateDirectories:YES attributes:nil error:nil];

}

+ (void)writeToFile:(NSString*)relativePath content:(NSString*)content isAppend:(BOOL)isAppend inStorage:(NSString*)storage {
Expand Down Expand Up @@ -105,7 +104,7 @@ + (BOOL)addSkipBackupAttributeToItemAtPath:(NSString *) filePathString
{
NSURL* URL= [NSURL fileURLWithPath: filePathString];
assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

NSError *error = nil;
BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
forKey: NSURLIsExcludedFromBackupKey error: &error];
Expand Down Expand Up @@ -135,12 +134,11 @@ + (NSString*)moveFileFromUrl:(NSURL*)location toRelativePath:(NSString*)relative

RCT_EXPORT_MODULE()

RCT_EXPORT_METHOD(writeToFile:(NSString*)relativePath content:(NSString*)content inStorage:(NSString*)storage resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
[RNFileSystem writeToFile:relativePath content:content inStorage:storage];
RCT_EXPORT_METHOD(writeToFile:(NSString*)relativePath content:(NSString*)content isAppend:(BOOL)isAppend inStorage:(NSString*)storage resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
[RNFileSystem writeToFile:relativePath content:content isAppend:(BOOL)isAppend inStorage:storage];
resolve([NSNumber numberWithBool:YES]);
}


RCT_EXPORT_METHOD(readFile:(NSString*)relativePath inStorage:(NSString*)storage resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
NSError *error;
NSString *content = [RNFileSystem readFile:relativePath inStorage:storage error:&error];
Expand Down
31 changes: 15 additions & 16 deletions modules/FileSystem.js
@@ -1,38 +1,37 @@
import ReactNative from 'react-native';
import ReactNative from 'react-native'

// noinspection JSUnresolvedVariable
const RNFileSystem = ReactNative.NativeModules.RNFileSystem;
const RNFileSystem = ReactNative.NativeModules.RNFileSystem

export default class FileSystem {

static storage = {
backedUp: 'BACKED_UP',
important: 'IMPORTANT',
auxiliary: 'AUXILIARY',
temporary: 'TEMPORARY',
temporary: 'TEMPORARY'
};

static async writeToFile(path, contents, isAppend = false, storage = FileSystem.storage.backedUp) {
return await RNFileSystem.writeToFile(path, contents, isAppend, storage);
static async writeToFile (path, contents, isAppend = false, storage = FileSystem.storage.backedUp) {
return RNFileSystem.writeToFile(path, contents, isAppend, storage)
}

static async readFile(path, storage = FileSystem.storage.backedUp) {
return await RNFileSystem.readFile(path, storage);
static async readFile (path, storage = FileSystem.storage.backedUp) {
return RNFileSystem.readFile(path, storage)
}

static async delete(path, storage = FileSystem.storage.backedUp) {
return await RNFileSystem.delete(path, storage);
static async delete (path, storage = FileSystem.storage.backedUp) {
return RNFileSystem.delete(path, storage)
}

static async fileExists(path, storage = FileSystem.storage.backedUp) {
return await RNFileSystem.fileExists(path, storage);
static async fileExists (path, storage = FileSystem.storage.backedUp) {
return RNFileSystem.fileExists(path, storage)
}

static async directoryExists(path, storage = FileSystem.storage.backedUp) {
return await RNFileSystem.directoryExists(path, storage);
static async directoryExists (path, storage = FileSystem.storage.backedUp) {
return RNFileSystem.directoryExists(path, storage)
}

static absolutePath(path, storage = FileSystem.storage.backedUp) {
return RNFileSystem[storage] + '/' + path;
static absolutePath (path, storage = FileSystem.storage.backedUp) {
return RNFileSystem[storage] + '/' + path
}
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "react-native-filesystem-v1",
"description": "Simple file system API for iOS & Android & Windows.",
"author": "Ben Wixen <benwixen@gmail.com>, HuyNQ <huy@huynq.net>",
"version": "0.10.6",
"version": "0.10.7",
"main": "modules/FileSystem.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit 5e3d029

Please sign in to comment.