You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* upstream/0.10.9:
Fixed problem with type casting (wkh237#513)
My proposed 0.10.9 changes (wkh237#489)
wkh237#268 Cancelled task should not trigger `then` promise function
Add ability to cancel android DownloadManager fetches (wkh237#502)
Fix iOS initialization race condition (wkh237#499)
prevent UIApplication methods from being called on background thread (wkh237#486)
Implemenet fs.hash() -- wkh237#439 "Feature: Calculate file hash" (wkh237#476)
I forgot one error string for the Android readFile() method (wkh237#475)
Fix for wkh237#467 (wkh237#472)
Fix for issue wkh237#468, wkh237#461, wkh237#460 and minor cleanup (wkh237#469)
When using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.
653
655
656
+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
657
+
658
+
```js
659
+
RNFetchBlob.fs.writeStream(
660
+
PATH_TO_FILE,
661
+
// encoding, should be one of `base64`, `utf8`, `ascii`
662
+
'utf8',
663
+
// should data append to existing content ?
664
+
true
665
+
)
666
+
.then(ofstream=>ofstream.write('foo'))
667
+
.then(ofstream=>ofstream.write('bar'))
668
+
.then(ofstream=>ofstream.write('foobar'))
669
+
.then(ofstream=>ofstream.close())
670
+
.catch(console.error)
671
+
```
672
+
673
+
or
674
+
675
+
```js
676
+
RNFetchBlob.fs.writeStream(
677
+
PATH_TO_FILE,
678
+
// encoding, should be one of `base64`, `utf8`, `ascii`
679
+
'utf8',
680
+
// should data append to existing content ?
681
+
true
682
+
)
683
+
.then(stream=>Promise.all([
684
+
stream.write('foo'),
685
+
stream.write('bar'),
686
+
stream.write('foobar')
687
+
]))
688
+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
689
+
.then(([stream]) =>stream.close())
690
+
.catch(console.error)
691
+
```
692
+
693
+
You should **NOT** do something like this:
694
+
654
695
```js
655
696
RNFetchBlob.fs.writeStream(
656
697
PATH_TO_FILE,
@@ -659,13 +700,18 @@ RNFetchBlob.fs.writeStream(
659
700
// should data append to existing content ?
660
701
true)
661
702
.then((ofstream) => {
703
+
// BAD IDEA - Don't do this, those writes are unchecked:
662
704
ofstream.write('foo')
663
705
ofstream.write('bar')
664
706
ofstream.close()
665
707
})
666
-
708
+
.catch(console.error) // Cannot catch any write() errors!
667
709
```
668
710
711
+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
712
+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
713
+
That code may _seem_ to work if there are no errors, but those writes are of the type "fire and forget": You start them and then turn away and never know if they really succeeded.
714
+
669
715
### Cache File Management
670
716
671
717
When using `fileCache` or `path` options along with `fetch` API, response data will automatically store into the file system. The files will **NOT** removed unless you `unlink` it. There're several ways to remove the files
promise.reject("RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"), "RNFetchblob.addCompleteDownload can not resolve URI:" + path);
358
+
promise.reject("EINVAL", "RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"));
0 commit comments