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
Copy file name to clipboardExpand all lines: README.md
+54-20Lines changed: 54 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,3 @@
1
-
## New Maintainers
2
-
3
-
We make quite a bit of use of react-native-fetch-blob at Jolt and would like to maintain the project. Feel free to open issues, PRs, etc. here as you would on the original repository. We will be investigating a new npm namespace under which to publish future versions of this library.
4
-
5
-
<br>
6
-
7
-
## About Pull Requests
8
-
9
-
Bugfixes should be applied to the `0.10.9` branch and new features should be applied to the `0.11.0`. Documentation/README updates can be applied directly to `master`.
<Image source={{ uri :'data:image/png,base64'+ data }}/>
650
+
<Image source={{ uri :'data:image/png,base64'+ data }}
661
651
})
662
652
})
663
653
```
664
654
665
655
When using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.
666
656
657
+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
658
+
659
+
```js
660
+
RNFetchBlob.fs.writeStream(
661
+
PATH_TO_FILE,
662
+
// encoding, should be one of `base64`, `utf8`, `ascii`
663
+
'utf8',
664
+
// should data append to existing content ?
665
+
true
666
+
)
667
+
.then(ofstream=>ofstream.write('foo'))
668
+
.then(ofstream=>ofstream.write('bar'))
669
+
.then(ofstream=>ofstream.write('foobar'))
670
+
.then(ofstream=>ofstream.close())
671
+
.catch(console.error)
672
+
```
673
+
674
+
or
675
+
676
+
```js
677
+
RNFetchBlob.fs.writeStream(
678
+
PATH_TO_FILE,
679
+
// encoding, should be one of `base64`, `utf8`, `ascii`
680
+
'utf8',
681
+
// should data append to existing content ?
682
+
true
683
+
)
684
+
.then(stream=>Promise.all([
685
+
stream.write('foo'),
686
+
stream.write('bar'),
687
+
stream.write('foobar')
688
+
]))
689
+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
690
+
.then(([stream]) =>stream.close())
691
+
.catch(console.error)
692
+
```
693
+
694
+
You should **NOT** do something like this:
695
+
667
696
```js
668
697
RNFetchBlob.fs.writeStream(
669
698
PATH_TO_FILE,
@@ -672,13 +701,18 @@ RNFetchBlob.fs.writeStream(
672
701
// should data append to existing content ?
673
702
true)
674
703
.then((ofstream) => {
704
+
// BAD IDEA - Don't do this, those writes are unchecked:
675
705
ofstream.write('foo')
676
706
ofstream.write('bar')
677
707
ofstream.close()
678
708
})
679
-
709
+
.catch(console.error) // Cannot catch any write() errors!
680
710
```
681
711
712
+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
713
+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
714
+
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.
715
+
682
716
### Cache File Management
683
717
684
718
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
@@ -808,4 +842,4 @@ See [release notes](https://github.com/wkh237/react-native-fetch-blob/releases)
808
842
### Development
809
843
810
844
If you're interested in hacking this module, check our [development guide](https://github.com/wkh237/react-native-fetch-blob/wiki/Home), there might be some helpful information.
0 commit comments