@@ -344,24 +344,27 @@ When calling `readStream` method, you have to `open` the stream, and start to re
344
344
345
345
``` js
346
346
let data = ' '
347
- let ifstream = RNFetchBlob .readStream (
347
+ RNFetchBlob .readStream (
348
348
// encoding, should be one of `base64`, `utf8`, `ascii`
349
349
' base64' ,
350
350
// file path
351
351
PATH_TO_THE_FILE ,
352
352
// (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)
353
353
// when reading file in BASE64 encoding, buffer size must be multiples of 3.
354
354
4095 )
355
- ifstream .onData ((chunk ) => {
356
- // when encoding is `ascii`, chunk will be an array contains numbers
357
- // otherwise it will be a string
358
- data += chunk
359
- })
360
- ifstream .onError ((err ) => {
361
- console .log (' oops' , err)
362
- })
363
- ifstream .onEnd (() => {
364
- < Image source= {{ uri : ' data:image/png,base64' + data }}
355
+ .then ((ifstream ) => {
356
+ ifstream .open ()
357
+ ifstream .onData ((chunk ) => {
358
+ // when encoding is `ascii`, chunk will be an array contains numbers
359
+ // otherwise it will be a string
360
+ data += chunk
361
+ })
362
+ ifstream .onError ((err ) => {
363
+ console .log (' oops' , err)
364
+ })
365
+ ifstream .onEnd (() => {
366
+ < Image source= {{ uri : ' data:image/png,base64' + data }}
367
+ })
365
368
})
366
369
```
367
370
@@ -496,10 +499,10 @@ RNFetchBlob.base64.decode(data)
496
499
497
500
This method returns common used folders:
498
501
499
- - DocumentDir
500
- - CacheDir
501
- - DCIMDir (Android Only)
502
- - DownloadDir (Android Only)
502
+ * DocumentDir
503
+ * CacheDir
504
+ * DCIMDir (Android Only)
505
+ * DownloadDir (Android Only)
503
506
504
507
example
505
508
@@ -580,6 +583,44 @@ Buffer size of read stream, default to `4096` and `4095`(when encoding is `base6
580
583
581
584
` readStream ` returns a promise which will resolve ` RNFetchBlobReadStream ` .
582
585
586
+ ``` js
587
+ // read using `utf8`
588
+ RNFetchBlob .fs .readStream (PATH_TO_READ , ' utf8' )
589
+ .then ((stream ) => {
590
+ let data = ' '
591
+ stream .open ()
592
+ stream .onData ((chunk ) => {
593
+ chunk += data
594
+ })
595
+ stream .onEnd (() => {
596
+ console .log (data)
597
+ })
598
+ })
599
+ // read using `ascii`
600
+ RNFetchBlob .fs .readStream (PATH_TO_READ , ' ascii' )
601
+ .then ((stream ) => {
602
+ let data = []
603
+ stream .open ()
604
+ stream .onData ((chunk ) => {
605
+ data = data .concat (data)
606
+ })
607
+ stream .onEnd (() => {
608
+ console .log (data)
609
+ })
610
+ })
611
+ // read using `base64`
612
+ RNFetchBlob .fs .readStream (PATH_TO_READ , ' base64' )
613
+ .then ((stream ) => {
614
+ let data = ' '
615
+ stream .open ()
616
+ stream .onData ((chunk ) => {
617
+ data += chunk
618
+ })
619
+ stream .onEnd (() => {
620
+ console .log (data)
621
+ })
622
+ })
623
+ ```
583
624
584
625
#### mkdir(path: string ): Promise
585
626
0 commit comments