@@ -109,12 +109,19 @@ + (BOOL)requiresMainQueueSetup
109
109
110
110
RCT_EXPORT_METHOD (writeFile:(NSString *)filepath
111
111
contents:(NSString *)base64Content
112
+ options:(NSDictionary *)options
112
113
resolver:(RCTPromiseResolveBlock)resolve
113
114
rejecter:(RCTPromiseRejectBlock)reject)
114
115
{
115
116
NSData *data = [[NSData alloc ] initWithBase64EncodedString: base64Content options: NSDataBase64DecodingIgnoreUnknownCharacters ];
116
117
117
- BOOL success = [[NSFileManager defaultManager ] createFileAtPath: filepath contents: data attributes: nil ];
118
+ NSMutableDictionary *attributes = [[NSMutableDictionary alloc ] init ];
119
+
120
+ if ([options objectForKey: @" NSFileProtectionKey" ]) {
121
+ [attributes setValue: [options objectForKey: @" NSFileProtectionKey" ] forKey: @" NSFileProtectionKey" ];
122
+ }
123
+
124
+ BOOL success = [[NSFileManager defaultManager ] createFileAtPath: filepath contents: data attributes: attributes];
118
125
119
126
if (!success) {
120
127
return reject (@" ENOENT" , [NSString stringWithFormat: @" ENOENT: no such file or directory, open '%@ '" , filepath], nil );
@@ -220,8 +227,14 @@ + (BOOL)requiresMainQueueSetup
220
227
{
221
228
NSFileManager *manager = [NSFileManager defaultManager ];
222
229
230
+ NSMutableDictionary *attributes = [[NSMutableDictionary alloc ] init ];
231
+
232
+ if ([options objectForKey: @" NSFileProtectionKey" ]) {
233
+ [attributes setValue: [options objectForKey: @" NSFileProtectionKey" ] forKey: @" NSFileProtectionKey" ];
234
+ }
235
+
223
236
NSError *error = nil ;
224
- BOOL success = [manager createDirectoryAtPath: filepath withIntermediateDirectories: YES attributes: nil error: &error];
237
+ BOOL success = [manager createDirectoryAtPath: filepath withIntermediateDirectories: YES attributes: attributes error: &error];
225
238
226
239
if (!success) {
227
240
return [self reject: reject withError: error];
@@ -385,6 +398,7 @@ + (BOOL)requiresMainQueueSetup
385
398
386
399
RCT_EXPORT_METHOD (moveFile:(NSString *)filepath
387
400
destPath:(NSString *)destPath
401
+ options:(NSDictionary *)options
388
402
resolver:(RCTPromiseResolveBlock)resolve
389
403
rejecter:(RCTPromiseRejectBlock)reject)
390
404
{
@@ -397,11 +411,22 @@ + (BOOL)requiresMainQueueSetup
397
411
return [self reject: reject withError: error];
398
412
}
399
413
414
+ if ([options objectForKey: @" NSFileProtectionKey" ]) {
415
+ NSMutableDictionary *attributes = [[NSMutableDictionary alloc ] init ];
416
+ [attributes setValue: [options objectForKey: @" NSFileProtectionKey" ] forKey: @" NSFileProtectionKey" ];
417
+ BOOL updateSuccess = [manager setAttributes: attributes ofItemAtPath: destPath error: &error];
418
+
419
+ if (!updateSuccess) {
420
+ return [self reject: reject withError: error];
421
+ }
422
+ }
423
+
400
424
resolve (nil );
401
425
}
402
426
403
427
RCT_EXPORT_METHOD (copyFile:(NSString *)filepath
404
428
destPath:(NSString *)destPath
429
+ options:(NSDictionary *)options
405
430
resolver:(RCTPromiseResolveBlock)resolve
406
431
rejecter:(RCTPromiseRejectBlock)reject)
407
432
{
@@ -414,6 +439,16 @@ + (BOOL)requiresMainQueueSetup
414
439
return [self reject: reject withError: error];
415
440
}
416
441
442
+ if ([options objectForKey: @" NSFileProtectionKey" ]) {
443
+ NSMutableDictionary *attributes = [[NSMutableDictionary alloc ] init ];
444
+ [attributes setValue: [options objectForKey: @" NSFileProtectionKey" ] forKey: @" NSFileProtectionKey" ];
445
+ BOOL updateSuccess = [manager setAttributes: attributes ofItemAtPath: destPath error: &error];
446
+
447
+ if (!updateSuccess) {
448
+ return [self reject: reject withError: error];
449
+ }
450
+ }
451
+
417
452
resolve (nil );
418
453
}
419
454
@@ -868,8 +903,12 @@ - (NSDictionary *)constantsToExport
868
903
@" RNFSTemporaryDirectoryPath" : NSTemporaryDirectory (),
869
904
@" RNFSLibraryDirectoryPath" : [self getPathForDirectory: NSLibraryDirectory],
870
905
@" RNFSFileTypeRegular" : NSFileTypeRegular ,
871
- @" RNFSFileTypeDirectory" : NSFileTypeDirectory
872
- };
906
+ @" RNFSFileTypeDirectory" : NSFileTypeDirectory ,
907
+ @" RNFSFileProtectionComplete" : NSFileProtectionComplete ,
908
+ @" RNFSFileProtectionCompleteUnlessOpen" : NSFileProtectionCompleteUnlessOpen ,
909
+ @" RNFSFileProtectionCompleteUntilFirstUserAuthentication" : NSFileProtectionCompleteUntilFirstUserAuthentication ,
910
+ @" RNFSFileProtectionNone" : NSFileProtectionNone
911
+ };
873
912
}
874
913
875
914
+(void )setCompletionHandlerForIdentifier : (NSString *)identifier completionHandler : (CompletionHandler)completionHandler
0 commit comments