|
@@ -727,7 +727,7 @@ public class RNFetchBlobFS {
|
727
|
727
|
* @param encoding Encoding of initial data.
|
728
|
728
|
* @param callback RCT bridge callback.
|
729
|
729
|
*/
|
730
|
|
- static void createFile(String path, String data, String encoding, Callback callback) {
|
|
730
|
+ static void createFile(String path, String data, String encoding, Promise promise) {
|
731
|
731
|
try {
|
732
|
732
|
File dest = new File(path);
|
733
|
733
|
boolean created = dest.createNewFile();
|
|
@@ -735,7 +735,7 @@ public class RNFetchBlobFS {
|
735
|
735
|
String orgPath = data.replace(RNFetchBlobConst.FILE_PREFIX, "");
|
736
|
736
|
File src = new File(orgPath);
|
737
|
737
|
if(!src.exists()) {
|
738
|
|
- callback.invoke("RNfetchBlob writeFileError", "source file : " + data + "not exists");
|
|
738
|
+ promise.reject("RNfetchBlob writeFileError", "source file : " + data + "not exists");
|
739
|
739
|
return ;
|
740
|
740
|
}
|
741
|
741
|
FileInputStream fin = new FileInputStream(src);
|
|
@@ -751,15 +751,15 @@ public class RNFetchBlobFS {
|
751
|
751
|
}
|
752
|
752
|
else {
|
753
|
753
|
if (!created) {
|
754
|
|
- 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.");
|
|
754
|
+ Promise.reject("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.");
|
755
|
755
|
return;
|
756
|
756
|
}
|
757
|
757
|
OutputStream ostream = new FileOutputStream(dest);
|
758
|
758
|
ostream.write(RNFetchBlobFS.stringToBytes(data, encoding));
|
759
|
759
|
}
|
760
|
|
- callback.invoke(null, path);
|
|
760
|
+ promise.resolve(path);
|
761
|
761
|
} catch(Exception err) {
|
762
|
|
- callback.invoke(err.getLocalizedMessage());
|
|
762
|
+ promise.reject(err.getLocalizedMessage());
|
763
|
763
|
}
|
764
|
764
|
}
|
765
|
765
|
|
|
@@ -769,16 +769,16 @@ public class RNFetchBlobFS {
|
769
|
769
|
* @param data Content of new file
|
770
|
770
|
* @param callback JS context callback
|
771
|
771
|
*/
|
772
|
|
- static void createFileASCII(String path, ReadableArray data, Callback callback) {
|
|
772
|
+ static void createFileASCII(String path, ReadableArray data, Promise promise) {
|
773
|
773
|
try {
|
774
|
774
|
File dest = new File(path);
|
775
|
775
|
if(dest.exists()) {
|
776
|
|
- callback.invoke("create file error: failed to create file at path `" + path + "`, file already exists.");
|
|
776
|
+ promise.reject("create file error: failed to create file at path `" + path + "`, file already exists.");
|
777
|
777
|
return;
|
778
|
778
|
}
|
779
|
779
|
boolean created = dest.createNewFile();
|
780
|
780
|
if(!created) {
|
781
|
|
- callback.invoke("create file error: failed to create file at path `" + path + "` for its parent path may not exists");
|
|
781
|
+ promise.reject("create file error: failed to create file at path `" + path + "` for its parent path may not exists");
|
782
|
782
|
return;
|
783
|
783
|
}
|
784
|
784
|
OutputStream ostream = new FileOutputStream(dest);
|
|
@@ -788,9 +788,9 @@ public class RNFetchBlobFS {
|
788
|
788
|
}
|
789
|
789
|
ostream.write(chunk);
|
790
|
790
|
chunk = null;
|
791
|
|
- callback.invoke(null, path);
|
|
791
|
+ promise.resolve(path);
|
792
|
792
|
} catch(Exception err) {
|
793
|
|
- callback.invoke(err.getLocalizedMessage());
|
|
793
|
+ promise.reject(err.getLocalizedMessage());
|
794
|
794
|
}
|
795
|
795
|
}
|
796
|
796
|
|