|
@@ -131,6 +131,7 @@ RCT_EXPORT_METHOD(createFile:(NSString *)path data:(NSString *)data encoding:(NS
|
131
|
131
|
callback(@[[NSString stringWithFormat:@"failed to create new file at path %@ please ensure the folder exists"]]);
|
132
|
132
|
|
133
|
133
|
}
|
|
134
|
+
|
134
|
135
|
#pragma mark - fs.createFileASCII
|
135
|
136
|
// method for create file with ASCII content
|
136
|
137
|
RCT_EXPORT_METHOD(createFileASCII:(NSString *)path data:(NSArray *)dataArray callback:(RCTResponseSenderBlock)callback) {
|
|
@@ -159,17 +160,20 @@ RCT_EXPORT_METHOD(exists:(NSString *)path callback:(RCTResponseSenderBlock)callb
|
159
|
160
|
}
|
160
|
161
|
|
161
|
162
|
#pragma mark - fs.writeFile
|
162
|
|
-RCT_EXPORT_METHOD(writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
|
163
|
+RCT_EXPORT_METHOD(writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
164
|
+{
|
163
|
165
|
[RNFetchBlobFS writeFile:path encoding:[NSString stringWithString:encoding] data:data append:append resolver:resolve rejecter:reject];
|
164
|
|
-})
|
|
166
|
+}
|
165
|
167
|
|
166
|
168
|
#pragma mark - fs.writeArray
|
167
|
|
-RCT_EXPORT_METHOD(writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
|
169
|
+RCT_EXPORT_METHOD(writeFileArray:(NSString *)path data:(NSArray *)data append:(BOOL)append resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
170
|
+{
|
168
|
171
|
[RNFetchBlobFS writeFileArray:path data:data append:append resolver:resolve rejecter:reject];
|
169
|
|
-})
|
|
172
|
+}
|
170
|
173
|
|
171
|
174
|
#pragma mark - fs.writeStream
|
172
|
|
-RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding appendData:(BOOL)append callback:(RCTResponseSenderBlock)callback) {
|
|
175
|
+RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding appendData:(BOOL)append callback:(RCTResponseSenderBlock)callback)
|
|
176
|
+{
|
173
|
177
|
RNFetchBlobFS * fileStream = [[RNFetchBlobFS alloc] initWithBridgeRef:self.bridge];
|
174
|
178
|
NSFileManager * fm = [NSFileManager defaultManager];
|
175
|
179
|
BOOL isDir = nil;
|
|
@@ -183,7 +187,8 @@ RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding
|
183
|
187
|
}
|
184
|
188
|
|
185
|
189
|
#pragma mark - fs.writeArrayChunk
|
186
|
|
-RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)dataArray callback:(RCTResponseSenderBlock) callback) {
|
|
190
|
+RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)dataArray callback:(RCTResponseSenderBlock) callback)
|
|
191
|
+{
|
187
|
192
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
188
|
193
|
char * bytes = (char *) malloc([dataArray count]);
|
189
|
194
|
for(int i = 0; i < dataArray.count; i++) {
|
|
@@ -197,21 +202,24 @@ RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)data
|
197
|
202
|
}
|
198
|
203
|
|
199
|
204
|
#pragma mark - fs.writeChunk
|
200
|
|
-RCT_EXPORT_METHOD(writeChunk:(NSString *)streamId withData:(NSString *)data callback:(RCTResponseSenderBlock) callback) {
|
|
205
|
+RCT_EXPORT_METHOD(writeChunk:(NSString *)streamId withData:(NSString *)data callback:(RCTResponseSenderBlock) callback)
|
|
206
|
+{
|
201
|
207
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
202
|
208
|
[fs writeEncodeChunk:data];
|
203
|
209
|
callback(@[[NSNull null]]);
|
204
|
210
|
}
|
205
|
211
|
|
206
|
212
|
#pragma mark - fs.closeStream
|
207
|
|
-RCT_EXPORT_METHOD(closeStream:(NSString *)streamId callback:(RCTResponseSenderBlock) callback) {
|
|
213
|
+RCT_EXPORT_METHOD(closeStream:(NSString *)streamId callback:(RCTResponseSenderBlock) callback)
|
|
214
|
+{
|
208
|
215
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
209
|
216
|
[fs closeOutStream];
|
210
|
217
|
callback(@[[NSNull null], @YES]);
|
211
|
218
|
}
|
212
|
219
|
|
213
|
220
|
#pragma mark - unlink
|
214
|
|
-RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
|
221
|
+RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) callback)
|
|
222
|
+{
|
215
|
223
|
NSError * error = nil;
|
216
|
224
|
NSString * tmpPath = nil;
|
217
|
225
|
[[NSFileManager defaultManager] removeItemAtPath:path error:&error];
|
|
@@ -222,7 +230,8 @@ RCT_EXPORT_METHOD(unlink:(NSString *)path callback:(RCTResponseSenderBlock) call
|
222
|
230
|
}
|
223
|
231
|
|
224
|
232
|
#pragma mark - fs.removeSession
|
225
|
|
-RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBlock) callback) {
|
|
233
|
+RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBlock) callback)
|
|
234
|
+{
|
226
|
235
|
NSError * error = nil;
|
227
|
236
|
NSString * tmpPath = nil;
|
228
|
237
|
|
|
@@ -238,7 +247,8 @@ RCT_EXPORT_METHOD(removeSession:(NSArray *)paths callback:(RCTResponseSenderBloc
|
238
|
247
|
}
|
239
|
248
|
|
240
|
249
|
#pragma mark - fs.ls
|
241
|
|
-RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
|
250
|
+RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback)
|
|
251
|
+{
|
242
|
252
|
NSFileManager* fm = [NSFileManager defaultManager];
|
243
|
253
|
BOOL exist = nil;
|
244
|
254
|
BOOL isDir = nil;
|
|
@@ -258,7 +268,8 @@ RCT_EXPORT_METHOD(ls:(NSString *)path callback:(RCTResponseSenderBlock) callback
|
258
|
268
|
}
|
259
|
269
|
|
260
|
270
|
#pragma mark - fs.stat
|
261
|
|
-RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback) {
|
|
271
|
+RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) callback)
|
|
272
|
+{
|
262
|
273
|
|
263
|
274
|
[RNFetchBlobFS getPathFromUri:target completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
|
264
|
275
|
__block NSMutableArray * result;
|
|
@@ -297,7 +308,8 @@ RCT_EXPORT_METHOD(stat:(NSString *)target callback:(RCTResponseSenderBlock) call
|
297
|
308
|
}
|
298
|
309
|
|
299
|
310
|
#pragma mark - fs.lstat
|
300
|
|
-RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
|
311
|
+RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callback)
|
|
312
|
+{
|
301
|
313
|
NSFileManager* fm = [NSFileManager defaultManager];
|
302
|
314
|
BOOL exist = nil;
|
303
|
315
|
BOOL isDir = nil;
|
|
@@ -331,7 +343,8 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
|
331
|
343
|
}
|
332
|
344
|
|
333
|
345
|
#pragma mark - fs.cp
|
334
|
|
-RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
|
|
346
|
+RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback)
|
|
347
|
+{
|
335
|
348
|
|
336
|
349
|
// path = [RNFetchBlobFS getPathOfAsset:path];
|
337
|
350
|
[RNFetchBlobFS getPathFromUri:src completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
|
|
@@ -356,7 +369,8 @@ RCT_EXPORT_METHOD(cp:(NSString*)src toPath:(NSString *)dest callback:(RCTRespons
|
356
|
369
|
|
357
|
370
|
|
358
|
371
|
#pragma mark - fs.mv
|
359
|
|
-RCT_EXPORT_METHOD(mv:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
|
|
372
|
+RCT_EXPORT_METHOD(mv:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback)
|
|
373
|
+{
|
360
|
374
|
NSError * error = nil;
|
361
|
375
|
BOOL result = [[NSFileManager defaultManager] moveItemAtURL:[NSURL fileURLWithPath:path] toURL:[NSURL fileURLWithPath:dest] error:&error];
|
362
|
376
|
|
|
@@ -368,7 +382,8 @@ RCT_EXPORT_METHOD(mv:(NSString *)path toPath:(NSString *)dest callback:(RCTRespo
|
368
|
382
|
}
|
369
|
383
|
|
370
|
384
|
#pragma mark - fs.mkdir
|
371
|
|
-RCT_EXPORT_METHOD(mkdir:(NSString *)path callback:(RCTResponseSenderBlock) callback) {
|
|
385
|
+RCT_EXPORT_METHOD(mkdir:(NSString *)path callback:(RCTResponseSenderBlock) callback)
|
|
386
|
+{
|
372
|
387
|
if([[NSFileManager defaultManager] fileExistsAtPath:path]) {
|
373
|
388
|
callback(@[@"mkdir failed, folder already exists"]);
|
374
|
389
|
return;
|
|
@@ -379,13 +394,14 @@ RCT_EXPORT_METHOD(mkdir:(NSString *)path callback:(RCTResponseSenderBlock) callb
|
379
|
394
|
}
|
380
|
395
|
|
381
|
396
|
#pragma mark - fs.readFile
|
382
|
|
-RCT_EXPORT_METHOD(readFile:(NSString *)path encoding:(NSString *)encoding resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject {
|
|
397
|
+RCT_EXPORT_METHOD(readFile:(NSString *)path encoding:(NSString *)encoding resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
|
398
|
+{
|
383
|
399
|
|
384
|
400
|
[RNFetchBlobFS readFile:path encoding:encoding resolver:resolve rejecter:reject onComplete:nil];
|
385
|
|
-})
|
|
401
|
+}
|
386
|
402
|
|
387
|
403
|
#pragma mark - fs.readStream
|
388
|
|
-RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId
|
|
404
|
+RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding bufferSize:(int)bufferSize tick:(int)tick streamId:(NSString *)streamId)
|
389
|
405
|
{
|
390
|
406
|
if(bufferSize == nil) {
|
391
|
407
|
if([[encoding lowercaseString] isEqualToString:@"base64"])
|
|
@@ -397,10 +413,11 @@ RCT_EXPORT_METHOD(readStream:(NSString *)path withEncoding:(NSString *)encoding
|
397
|
413
|
dispatch_async(fsQueue, ^{
|
398
|
414
|
[RNFetchBlobFS readStream:path encoding:encoding bufferSize:bufferSize tick:tick streamId:streamId bridgeRef:_bridge];
|
399
|
415
|
});
|
400
|
|
-})
|
|
416
|
+}
|
401
|
417
|
|
402
|
418
|
#pragma mark - fs.getEnvionmentDirs
|
403
|
|
-RCT_EXPORT_METHOD(getEnvironmentDirs:(RCTResponseSenderBlock) callback) {
|
|
419
|
+RCT_EXPORT_METHOD(getEnvironmentDirs:(RCTResponseSenderBlock) callback)
|
|
420
|
+{
|
404
|
421
|
|
405
|
422
|
callback(@[
|
406
|
423
|
[RNFetchBlobFS getDocumentDir],
|
|
@@ -416,25 +433,27 @@ RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBl
|
416
|
433
|
}
|
417
|
434
|
|
418
|
435
|
#pragma mark - net.enableProgressReport
|
419
|
|
-RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count {
|
|
436
|
+RCT_EXPORT_METHOD(enableProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
|
|
437
|
+{
|
420
|
438
|
|
421
|
439
|
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
|
422
|
440
|
[RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
|
423
|
|
-})
|
|
441
|
+}
|
424
|
442
|
|
425
|
443
|
#pragma mark - net.enableUploadProgressReport
|
426
|
|
-RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count{
|
|
444
|
+RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
|
|
445
|
+{
|
427
|
446
|
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Upload interval:interval count:count];
|
428
|
447
|
[RNFetchBlobNetwork enableUploadProgress:taskId config:cfg];
|
429
|
|
-})
|
|
448
|
+}
|
430
|
449
|
|
431
|
450
|
#pragma mark - fs.slice
|
432
|
|
-RCT_EXPORT_METHOD(slice:(NSString *)src dest:(NSString *)dest start:(nonnull NSNumber *)start end:(nonnull NSNumber *)end resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
451
|
+RCT_EXPORT_METHOD(slice:(NSString *)src dest:(NSString *)dest start:(nonnull NSNumber *)start end:(nonnull NSNumber *)end resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
433
|
452
|
{
|
434
|
453
|
[RNFetchBlobFS slice:src dest:dest start:start end:end encode:@"" resolver:resolve rejecter:reject];
|
435
|
|
-})
|
|
454
|
+}
|
436
|
455
|
|
437
|
|
-RCT_EXPORT_METHOD(previewDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
456
|
+RCT_EXPORT_METHOD(previewDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
438
|
457
|
{
|
439
|
458
|
NSString * utf8uri = [uri stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
440
|
459
|
NSURL * url = [[NSURL alloc] initWithString:utf8uri];
|
|
@@ -450,11 +469,11 @@ RCT_EXPORT_METHOD(previewDocument:(NSString*)uri scheme:(NSString *)scheme resol
|
450
|
469
|
} else {
|
451
|
470
|
reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
|
452
|
471
|
}
|
453
|
|
-})
|
|
472
|
+}
|
454
|
473
|
|
455
|
474
|
# pragma mark - open file with UIDocumentInteractionController and delegate
|
456
|
475
|
|
457
|
|
-RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
476
|
+RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
458
|
477
|
{
|
459
|
478
|
NSString * utf8uri = [uri stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
460
|
479
|
NSURL * url = [[NSURL alloc] initWithString:utf8uri];
|
|
@@ -470,11 +489,11 @@ RCT_EXPORT_METHOD(openDocument:(NSString*)uri scheme:(NSString *)scheme resolver
|
470
|
489
|
} else {
|
471
|
490
|
reject(@"RNFetchBlob could not open document", @"scheme is not supported", nil);
|
472
|
491
|
}
|
473
|
|
-})
|
|
492
|
+}
|
474
|
493
|
|
475
|
494
|
# pragma mark - exclude from backup key
|
476
|
495
|
|
477
|
|
-RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
496
|
+RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
478
|
497
|
{
|
479
|
498
|
NSError *error = nil;
|
480
|
499
|
[ [NSURL URLWithString:url] setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
|
|
@@ -485,31 +504,32 @@ RCT_EXPORT_METHOD(excludeFromBackupKey:(NSString *)url resolver:(RCTPromiseResol
|
485
|
504
|
reject(@"RNFetchBlob could not open document", [error description], nil);
|
486
|
505
|
}
|
487
|
506
|
|
488
|
|
-})
|
|
507
|
+}
|
489
|
508
|
|
490
|
509
|
|
491
|
|
-RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback
|
|
510
|
+RCT_EXPORT_METHOD(df:(RCTResponseSenderBlock)callback)
|
492
|
511
|
{
|
493
|
512
|
[RNFetchBlobFS df:callback];
|
494
|
|
-})
|
|
513
|
+}
|
495
|
514
|
|
496
|
|
-- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
|
|
515
|
+- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller
|
|
516
|
+{
|
497
|
517
|
UIWindow *window = [UIApplication sharedApplication].keyWindow;
|
498
|
518
|
return window.rootViewController;
|
499
|
519
|
}
|
500
|
520
|
|
501
|
521
|
# pragma mark - getCookies
|
502
|
|
-RCT_EXPORT_METHOD(getCookies:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject
|
|
522
|
+RCT_EXPORT_METHOD(getCookies:(NSString *)url resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
|
503
|
523
|
{
|
504
|
524
|
resolve([RNFetchBlobNetwork getCookies:url]);
|
505
|
|
-})
|
|
525
|
+}
|
506
|
526
|
|
507
|
527
|
# pragma mark - check expired network events
|
508
|
528
|
|
509
|
|
-RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback
|
|
529
|
+RCT_EXPORT_METHOD(emitExpiredEvent:(RCTResponseSenderBlock)callback)
|
510
|
530
|
{
|
511
|
531
|
[RNFetchBlobNetwork emitExpiredTasks];
|
512
|
|
-})
|
|
532
|
+}
|
513
|
533
|
|
514
|
534
|
|
515
|
535
|
@end
|