Ben Hsieh пре 8 година
родитељ
комит
9c0e531e91

+ 5
- 9
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Прегледај датотеку

@@ -344,7 +344,6 @@ public class RNFetchBlobFS {
344 344
         try {
345 345
             stream.write(chunk);
346 346
             callback.invoke();
347
-            chunk = null;
348 347
         } catch (Exception e) {
349 348
             callback.invoke(e.getLocalizedMessage());
350 349
         }
@@ -431,8 +430,7 @@ public class RNFetchBlobFS {
431 430
 
432 431
         try {
433 432
 
434
-            String destFolder = new File(dest).getPath();
435
-            if(!new File(path).exists()) {
433
+            if(!isPathExists(path)) {
436 434
                 callback.invoke("cp error: source file at path`" + path + "` not exists");
437 435
                 return;
438 436
             }
@@ -490,7 +488,6 @@ public class RNFetchBlobFS {
490 488
             try {
491 489
                 String filename = path.replace(assetPrefix, "");
492 490
                 AssetFileDescriptor fd = RNFetchBlob.RCTContext.getAssets().openFd(filename);
493
-                // TODO : handle asset folder
494 491
                 callback.invoke(true, false);
495 492
             } catch (IOException e) {
496 493
                 callback.invoke(false, false);
@@ -512,14 +509,13 @@ public class RNFetchBlobFS {
512 509
     static void ls(String path, Callback callback) {
513 510
         path = normalizePath(path);
514 511
         File src = new File(path);
515
-        // TODO : handle asset folder
516
-        if(!src.exists() || !src.isDirectory()) {
512
+        if (!src.exists() || !src.isDirectory()) {
517 513
             callback.invoke("ls error: failed to list path `" + path + "` for it is not exist or it is not a folder");
518 514
             return;
519 515
         }
520
-        String [] files = new File(path).list();
516
+        String[] files = new File(path).list();
521 517
         WritableArray arg = Arguments.createArray();
522
-        for(String i : files) {
518
+        for (String i : files) {
523 519
             arg.pushString(i);
524 520
         }
525 521
         callback.invoke(null, arg);
@@ -527,7 +523,7 @@ public class RNFetchBlobFS {
527 523
 
528 524
     static void lstat(String path, final Callback callback) {
529 525
         path = normalizePath(path);
530
-        File src = new File(path);
526
+
531 527
         new AsyncTask<String, Integer, Integer>() {
532 528
             @Override
533 529
             protected Integer doInBackground(String ...args) {

+ 2
- 2
src/fs.js Прегледај датотеку

@@ -48,7 +48,7 @@ function session(name:string):RNFetchBlobSession {
48 48
   }
49 49
 }
50 50
 
51
-function addAssetPrefix(path:string):string {
51
+function asset(path:string):string {
52 52
   if(Platform.OS === 'ios') {
53 53
     // path from camera roll
54 54
     if(/^assets-library\:\/\//.test(path))
@@ -335,5 +335,5 @@ export default {
335 335
   lstat,
336 336
   scanFile,
337 337
   dirs,
338
-  addAssetPrefix
338
+  asset
339 339
 }

+ 7
- 0
src/ios/RNFetchBlob/RNFetchBlob.m Прегледај датотеку

@@ -334,6 +334,9 @@ RCT_EXPORT_METHOD(stat:(NSString *)path callback:(RCTResponseSenderBlock) callba
334 334
     BOOL exist = nil;
335 335
     BOOL isDir = nil;
336 336
     NSError * error = nil;
337
+    
338
+    path = [RNFetchBlobFS getPathOfAsset:path];
339
+    
337 340
     exist = [fm fileExistsAtPath:path isDirectory:&isDir];
338 341
     if(exist == NO) {
339 342
         callback(@[[NSString stringWithFormat:@"failed to list path `%@` for it is not exist or it is not exist", path]]);
@@ -352,6 +355,9 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
352 355
     NSFileManager* fm = [NSFileManager defaultManager];
353 356
     BOOL exist = nil;
354 357
     BOOL isDir = nil;
358
+    
359
+    path = [RNFetchBlobFS getPathOfAsset:path];
360
+    
355 361
     exist = [fm fileExistsAtPath:path isDirectory:&isDir];
356 362
     if(exist == NO) {
357 363
         callback(@[[NSString stringWithFormat:@"failed to list path `%@` for it is not exist or it is not exist", path]]);
@@ -380,6 +386,7 @@ RCT_EXPORT_METHOD(lstat:(NSString *)path callback:(RCTResponseSenderBlock) callb
380 386
 
381 387
 RCT_EXPORT_METHOD(cp:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
382 388
     NSError * error = nil;
389
+    path = [RNFetchBlobFS getPathOfAsset:path];
383 390
     BOOL result = [[NSFileManager defaultManager] copyItemAtURL:[NSURL fileURLWithPath:path] toURL:[NSURL fileURLWithPath:dest] error:&error];
384 391
     
385 392
     if(error == nil)