wkh237 преди 9 години
родител
ревизия
5910994e5a
променени са 1 файла, в които са добавени 56 реда и са изтрити 15 реда
  1. 56
    15
      README.md

+ 56
- 15
README.md Целия файл

344
 
344
 
345
 ```js
345
 ```js
346
 let data = ''
346
 let data = ''
347
-let ifstream = RNFetchBlob.readStream(
347
+RNFetchBlob.readStream(
348
     // encoding, should be one of `base64`, `utf8`, `ascii`
348
     // encoding, should be one of `base64`, `utf8`, `ascii`
349
     'base64',
349
     'base64',
350
     // file path
350
     // file path
352
     // (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)
352
     // (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)
353
     // when reading file in BASE64 encoding, buffer size must be multiples of 3.
353
     // when reading file in BASE64 encoding, buffer size must be multiples of 3.
354
     4095)
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
 
499
 
497
 This method returns common used folders:
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
 example 
507
 example 
505
 
508
 
580
 
583
 
581
 `readStream` returns a promise which will resolve `RNFetchBlobReadStream`.
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
 #### mkdir(path:string):Promise
625
 #### mkdir(path:string):Promise
585
 
626