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
+53-19Lines changed: 53 additions & 19 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 }}/>
641
+
<Image source={{ uri :'data:image/png,base64'+ data }}
652
642
})
653
643
})
654
644
```
655
645
656
646
When using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.
657
647
648
+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
649
+
650
+
```js
651
+
RNFetchBlob.fs.writeStream(
652
+
PATH_TO_FILE,
653
+
// encoding, should be one of `base64`, `utf8`, `ascii`
654
+
'utf8',
655
+
// should data append to existing content ?
656
+
true
657
+
)
658
+
.then(ofstream=>ofstream.write('foo'))
659
+
.then(ofstream=>ofstream.write('bar'))
660
+
.then(ofstream=>ofstream.write('foobar'))
661
+
.then(ofstream=>ofstream.close())
662
+
.catch(console.error)
663
+
```
664
+
665
+
or
666
+
667
+
```js
668
+
RNFetchBlob.fs.writeStream(
669
+
PATH_TO_FILE,
670
+
// encoding, should be one of `base64`, `utf8`, `ascii`
671
+
'utf8',
672
+
// should data append to existing content ?
673
+
true
674
+
)
675
+
.then(stream=>Promise.all([
676
+
stream.write('foo'),
677
+
stream.write('bar'),
678
+
stream.write('foobar')
679
+
]))
680
+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
681
+
.then(([stream]) =>stream.close())
682
+
.catch(console.error)
683
+
```
684
+
685
+
You should **NOT** do something like this:
686
+
658
687
```js
659
688
RNFetchBlob.fs.writeStream(
660
689
PATH_TO_FILE,
@@ -663,13 +692,18 @@ RNFetchBlob.fs.writeStream(
663
692
// should data append to existing content ?
664
693
true)
665
694
.then((ofstream) => {
695
+
// BAD IDEA - Don't do this, those writes are unchecked:
666
696
ofstream.write('foo')
667
697
ofstream.write('bar')
668
698
ofstream.close()
669
699
})
670
-
700
+
.catch(console.error) // Cannot catch any write() errors!
671
701
```
672
702
703
+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
704
+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
705
+
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.
706
+
673
707
### Cache File Management
674
708
675
709
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
0 commit comments