|
@@ -78,7 +78,7 @@ public class RNFetchBlobFS {
|
78
|
78
|
data = normalizePath(data);
|
79
|
79
|
File src = new File(data);
|
80
|
80
|
if(!src.exists()) {
|
81
|
|
- promise.reject("RNfetchBlob writeFileError", "source file : " + data + "not exists");
|
|
81
|
+ promise.reject("RNfetchBlob writeFile error", "source file : " + data + " does not exist");
|
82
|
82
|
fout.close();
|
83
|
83
|
return ;
|
84
|
84
|
}
|
|
@@ -100,7 +100,7 @@ public class RNFetchBlobFS {
|
100
|
100
|
fout.close();
|
101
|
101
|
promise.resolve(written);
|
102
|
102
|
} catch (Exception e) {
|
103
|
|
- promise.reject("RNFetchBlob writeFileError", e.getLocalizedMessage());
|
|
103
|
+ promise.reject("RNFetchBlob writeFile error", e.getLocalizedMessage());
|
104
|
104
|
}
|
105
|
105
|
}
|
106
|
106
|
|
|
@@ -127,7 +127,7 @@ public class RNFetchBlobFS {
|
127
|
127
|
os.close();
|
128
|
128
|
promise.resolve(data.size());
|
129
|
129
|
} catch (Exception e) {
|
130
|
|
- promise.reject("RNFetchBlob writeFileError", e.getLocalizedMessage());
|
|
130
|
+ promise.reject("RNFetchBlob writeFile error", e.getLocalizedMessage());
|
131
|
131
|
}
|
132
|
132
|
}
|
133
|
133
|
|
|
@@ -309,7 +309,8 @@ public class RNFetchBlobFS {
|
309
|
309
|
buffer = null;
|
310
|
310
|
|
311
|
311
|
} catch (Exception err) {
|
312
|
|
- emitStreamEvent(streamId, "warn", "Failed to convert data to "+encoding+" encoded string, this might due to the source data is not able to convert using this encoding.");
|
|
312
|
+ emitStreamEvent(streamId, "warn", "Failed to convert data to " + encoding +
|
|
313
|
+ " encoded string, this might due to the source data is not able to convert using this encoding.");
|
313
|
314
|
err.printStackTrace();
|
314
|
315
|
}
|
315
|
316
|
}
|
|
@@ -324,7 +325,7 @@ public class RNFetchBlobFS {
|
324
|
325
|
public void writeStream(String path, String encoding, boolean append, Callback callback) {
|
325
|
326
|
File dest = new File(path);
|
326
|
327
|
if(!dest.exists() || dest.isDirectory()) {
|
327
|
|
- callback.invoke("write stream error: target path `" + path + "` may not exists or it's a folder");
|
|
328
|
+ callback.invoke("target path `" + path + "` may not exist or it is a folder");
|
328
|
329
|
return;
|
329
|
330
|
}
|
330
|
331
|
try {
|
|
@@ -336,7 +337,7 @@ public class RNFetchBlobFS {
|
336
|
337
|
this.writeStreamInstance = fs;
|
337
|
338
|
callback.invoke(null, streamId);
|
338
|
339
|
} catch(Exception err) {
|
339
|
|
- callback.invoke("write stream error: failed to create write stream at path `"+path+"` "+ err.getLocalizedMessage());
|
|
340
|
+ callback.invoke("failed to create write stream at path `" + path + "` " + err.getLocalizedMessage());
|
340
|
341
|
}
|
341
|
342
|
|
342
|
343
|
}
|
|
@@ -433,12 +434,13 @@ public class RNFetchBlobFS {
|
433
|
434
|
static void mkdir(String path, Callback callback) {
|
434
|
435
|
File dest = new File(path);
|
435
|
436
|
if(dest.exists()) {
|
436
|
|
- callback.invoke("mkdir error: failed to create folder at `" + path + "` folder already exists");
|
|
437
|
+ callback.invoke("mkdir failed, folder already exists at " + path);
|
437
|
438
|
return;
|
438
|
439
|
}
|
439
|
440
|
dest.mkdirs();
|
440
|
441
|
callback.invoke();
|
441
|
442
|
}
|
|
443
|
+
|
442
|
444
|
/**
|
443
|
445
|
* Copy file to destination path
|
444
|
446
|
* @param path Source path
|
|
@@ -454,7 +456,7 @@ public class RNFetchBlobFS {
|
454
|
456
|
try {
|
455
|
457
|
|
456
|
458
|
if(!isPathExists(path)) {
|
457
|
|
- callback.invoke("cp error: source file at path`" + path + "` not exists");
|
|
459
|
+ callback.invoke("source file at path`" + path + "` does not exist");
|
458
|
460
|
return;
|
459
|
461
|
}
|
460
|
462
|
if(!new File(dest).exists())
|
|
@@ -495,7 +497,7 @@ public class RNFetchBlobFS {
|
495
|
497
|
static void mv(String path, String dest, Callback callback) {
|
496
|
498
|
File src = new File(path);
|
497
|
499
|
if(!src.exists()) {
|
498
|
|
- callback.invoke("mv error: source file at path `" + path + "` does not exists");
|
|
500
|
+ callback.invoke("source file at path `" + path + "` does not exist");
|
499
|
501
|
return;
|
500
|
502
|
}
|
501
|
503
|
src.renameTo(new File(dest));
|
|
@@ -535,7 +537,7 @@ public class RNFetchBlobFS {
|
535
|
537
|
path = normalizePath(path);
|
536
|
538
|
File src = new File(path);
|
537
|
539
|
if (!src.exists() || !src.isDirectory()) {
|
538
|
|
- callback.invoke("ls error: failed to list path `" + path + "` for it is not exist or it is not a folder");
|
|
540
|
+ callback.invoke("failed to list path `" + path + "` for it is not exist or it is not a folder");
|
539
|
541
|
return;
|
540
|
542
|
}
|
541
|
543
|
String[] files = new File(path).list();
|
|
@@ -559,7 +561,7 @@ public class RNFetchBlobFS {
|
559
|
561
|
src = normalizePath(src);
|
560
|
562
|
File source = new File(src);
|
561
|
563
|
if(!source.exists()) {
|
562
|
|
- promise.reject("RNFetchBlob.slice error", "source file : " + src + " not exists");
|
|
564
|
+ promise.reject("RNFetchBlob slice error", "source file : " + src + " does not exist");
|
563
|
565
|
return;
|
564
|
566
|
}
|
565
|
567
|
long size = source.length();
|
|
@@ -585,7 +587,7 @@ public class RNFetchBlobFS {
|
585
|
587
|
promise.resolve(dest);
|
586
|
588
|
} catch (Exception e) {
|
587
|
589
|
e.printStackTrace();
|
588
|
|
- promise.reject(e.getLocalizedMessage());
|
|
590
|
+ promise.reject("RNFetchBlob slice error", e.getLocalizedMessage());
|
589
|
591
|
}
|
590
|
592
|
}
|
591
|
593
|
|
|
@@ -597,18 +599,18 @@ public class RNFetchBlobFS {
|
597
|
599
|
protected Integer doInBackground(String ...args) {
|
598
|
600
|
WritableArray res = Arguments.createArray();
|
599
|
601
|
if(args[0] == null) {
|
600
|
|
- callback.invoke("lstat error: the path specified for lstat is either `null` or `undefined`.");
|
|
602
|
+ callback.invoke("the path specified for lstat is either `null` or `undefined`.");
|
601
|
603
|
return 0;
|
602
|
604
|
}
|
603
|
605
|
File src = new File(args[0]);
|
604
|
606
|
if(!src.exists()) {
|
605
|
|
- callback.invoke("lstat error: failed to list path `" + args[0] + "` for it is not exist or it is not a folder");
|
|
607
|
+ callback.invoke("failed to lstat path `" + args[0] + "` because it does not exist or it is not a folder");
|
606
|
608
|
return 0;
|
607
|
609
|
}
|
608
|
610
|
if(src.isDirectory()) {
|
609
|
611
|
String [] files = src.list();
|
610
|
612
|
for(String p : files) {
|
611
|
|
- res.pushMap(statFile ( src.getPath() + "/" + p));
|
|
613
|
+ res.pushMap(statFile(src.getPath() + "/" + p));
|
612
|
614
|
}
|
613
|
615
|
}
|
614
|
616
|
else {
|
|
@@ -630,7 +632,7 @@ public class RNFetchBlobFS {
|
630
|
632
|
path = normalizePath(path);
|
631
|
633
|
WritableMap result = statFile(path);
|
632
|
634
|
if(result == null)
|
633
|
|
- callback.invoke("stat error: failed to list path `" + path + "` for it is not exist or it is not a folder", null);
|
|
635
|
+ callback.invoke("failed to stat path `" + path + "` because it does not exist or it is not a folder", null);
|
634
|
636
|
else
|
635
|
637
|
callback.invoke(null, result);
|
636
|
638
|
} catch(Exception err) {
|
|
@@ -709,23 +711,24 @@ public class RNFetchBlobFS {
|
709
|
711
|
String orgPath = data.replace(RNFetchBlobConst.FILE_PREFIX, "");
|
710
|
712
|
File src = new File(orgPath);
|
711
|
713
|
if(!src.exists()) {
|
712
|
|
- callback.invoke("RNfetchBlob writeFileError", "source file : " + data + "not exists");
|
|
714
|
+ callback.invoke("source file : " + data + " does not exist");
|
713
|
715
|
return ;
|
714
|
716
|
}
|
715
|
717
|
FileInputStream fin = new FileInputStream(src);
|
716
|
718
|
OutputStream ostream = new FileOutputStream(dest);
|
717
|
|
- byte [] buffer = new byte [10240];
|
|
719
|
+ byte[] buffer = new byte[10240];
|
718
|
720
|
int read = fin.read(buffer);
|
719
|
|
- while(read > 0) {
|
|
721
|
+ while (read > 0) {
|
720
|
722
|
ostream.write(buffer, 0, read);
|
721
|
723
|
read = fin.read(buffer);
|
722
|
724
|
}
|
723
|
725
|
fin.close();
|
724
|
726
|
ostream.close();
|
725
|
|
- }
|
726
|
|
- else {
|
|
727
|
+ } else {
|
727
|
728
|
if (!created) {
|
728
|
|
- callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists, or the file already exists. If you intended to overwrite the existing file use fs.writeFile instead.");
|
|
729
|
+ callback.invoke("failed to create new file at path `" + path + "` because its parent path " +
|
|
730
|
+ "may not exist, or the file already exists. If you intended to overwrite the " +
|
|
731
|
+ "existing file use fs.writeFile instead.");
|
729
|
732
|
return;
|
730
|
733
|
}
|
731
|
734
|
OutputStream ostream = new FileOutputStream(dest);
|
|
@@ -747,12 +750,12 @@ public class RNFetchBlobFS {
|
747
|
750
|
try {
|
748
|
751
|
File dest = new File(path);
|
749
|
752
|
if(dest.exists()) {
|
750
|
|
- callback.invoke("create file error: failed to create file at path `" + path + "`, file already exists.");
|
|
753
|
+ callback.invoke("failed to create new file at path `" + path + "`, file already exists.");
|
751
|
754
|
return;
|
752
|
755
|
}
|
753
|
756
|
boolean created = dest.createNewFile();
|
754
|
757
|
if(!created) {
|
755
|
|
- callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists");
|
|
758
|
+ callback.invoke("failed to create new file at path `" + path + "` because its parent path may not exist");
|
756
|
759
|
return;
|
757
|
760
|
}
|
758
|
761
|
OutputStream ostream = new FileOutputStream(dest);
|