Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 5910994

Browse files
committed
Update README.md
1 parent dbe2015 commit 5910994

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

README.md

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,27 @@ When calling `readStream` method, you have to `open` the stream, and start to re
344344

345345
```js
346346
let data = ''
347-
let ifstream = RNFetchBlob.readStream(
347+
RNFetchBlob.readStream(
348348
// encoding, should be one of `base64`, `utf8`, `ascii`
349349
'base64',
350350
// file path
351351
PATH_TO_THE_FILE,
352352
// (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)
353353
// when reading file in BASE64 encoding, buffer size must be multiples of 3.
354354
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+
})
365368
})
366369
```
367370

@@ -496,10 +499,10 @@ RNFetchBlob.base64.decode(data)
496499

497500
This method returns common used folders:
498501

499-
- DocumentDir
500-
- CacheDir
501-
- DCIMDir (Android Only)
502-
- DownloadDir (Android Only)
502+
* DocumentDir
503+
* CacheDir
504+
* DCIMDir (Android Only)
505+
* DownloadDir (Android Only)
503506

504507
example
505508

@@ -580,6 +583,44 @@ Buffer size of read stream, default to `4096` and `4095`(when encoding is `base6
580583

581584
`readStream` returns a promise which will resolve `RNFetchBlobReadStream`.
582585

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+
```
583624

584625
#### mkdir(path:string):Promise
585626

0 commit comments

Comments
 (0)