Browse Source

Update README.md

Ben Hsieh 9 years ago
parent
commit
285d3ee0dc
1 changed files with 28 additions and 46 deletions
  1. 28
    46
      README.md

+ 28
- 46
README.md View File

96
 
96
 
97
 #### Download to storage directly
97
 #### Download to storage directly
98
 
98
 
99
-The simplest way is give a `fileCach` option to config, and set it to `true`. This will let the incoming response data stored in a temporary path **wihout** any file extension. 
99
+The simplest way is give a `fileCach` option to config, and set it to `true`. This will let the incoming response data stored in a temporary path **wihout** any file extension.
100
 
100
 
101
 **These files won't be removed automatically, please refer to [Cache File Management](#user-content-cache-file-management)**
101
 **These files won't be removed automatically, please refer to [Cache File Management](#user-content-cache-file-management)**
102
 
102
 
177
       mute : false
177
       mute : false
178
     }),
178
     }),
179
     'Content-Type' : 'application/octet-stream',
179
     'Content-Type' : 'application/octet-stream',
180
-    // here's the body you're going to send, should be a BASE64 encoded string 
181
-    // (you can use "base64" APIs to make one). 
180
+    // here's the body you're going to send, should be a BASE64 encoded string
181
+    // (you can use "base64" APIs to make one).
182
     // The data will be converted to "byte array"(say, blob) before request sent.  
182
     // The data will be converted to "byte array"(say, blob) before request sent.  
183
   }, base64ImageString)
183
   }, base64ImageString)
184
   .then((res) => {
184
   .then((res) => {
253
     'Content-Type' : 'multipart/form-data',
253
     'Content-Type' : 'multipart/form-data',
254
   }, [
254
   }, [
255
     // append field data from file path
255
     // append field data from file path
256
-    { 
256
+    {
257
       name : 'avatar',
257
       name : 'avatar',
258
       filename : 'avatar.png',
258
       filename : 'avatar.png',
259
       // Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file path
259
       // Change BASE64 encoded data to a file path with prefix `RNFetchBlob-file://` when the data comes from a file path
318
 
318
 
319
 #### File Access
319
 #### File Access
320
 
320
 
321
-File access APIs were made when developing `v0.5.0`, which helping us write tests, and was not planned to be a part of this module. However I realized that, it's hard to find a great solution to manage cached files, every one who use this moudle may need those APIs for there cases. 
321
+File access APIs were made when developing `v0.5.0`, which helping us write tests, and was not planned to be a part of this module. However I realized that, it's hard to find a great solution to manage cached files, every one who use this moudle may need those APIs for there cases.
322
 
322
 
323
 Here's the list of `fs` APIs
323
 Here's the list of `fs` APIs
324
 
324
 
340
 
340
 
341
 In `v0.5.0` we've added  `writeStream` and `readStream`, which allows your app read/write data from file path. This API creates a file stream, rather than convert whole data into BASE64 encoded string, it's handy when processing **large files**.
341
 In `v0.5.0` we've added  `writeStream` and `readStream`, which allows your app read/write data from file path. This API creates a file stream, rather than convert whole data into BASE64 encoded string, it's handy when processing **large files**.
342
 
342
 
343
-When calling `readStream` method, you have to `open` the stream, and start to read data. 
343
+When calling `readStream` method, you have to `open` the stream, and start to read data.
344
 
344
 
345
 ```js
345
 ```js
346
 let data = ''
346
 let data = ''
372
 
372
 
373
 ```js
373
 ```js
374
 let ofstream = RNFetchBlob.writeStream(
374
 let ofstream = RNFetchBlob.writeStream(
375
-    PATH_TO_FILE, 
375
+    PATH_TO_FILE,
376
     // encoding, should be one of `base64`, `utf8`, `ascii`
376
     // encoding, should be one of `base64`, `utf8`, `ascii`
377
     'utf8',
377
     'utf8',
378
     // should data append to existing content ?
378
     // should data append to existing content ?
444
 
444
 
445
 #### `config(options:RNFetchBlobConfig):fetch`
445
 #### `config(options:RNFetchBlobConfig):fetch`
446
 
446
 
447
+---
448
+
447
 `0.5.0`
449
 `0.5.0`
448
 
450
 
449
-Config API was introduced in `v0.5.0` which provides some options for the `fetch` task. 
451
+Config API was introduced in `v0.5.0` which provides some options for the `fetch` task.
450
 
452
 
451
 see [RNFetchBlobConfig](#user-content-rnfetchblobconfig)
453
 see [RNFetchBlobConfig](#user-content-rnfetchblobconfig)
452
 
454
 
453
 #### `fetch(method, url, headers, body):Promise<FetchBlobResponse>`
455
 #### `fetch(method, url, headers, body):Promise<FetchBlobResponse>`
454
 
456
 
457
+---
458
+
455
 `legacy`
459
 `legacy`
456
 
460
 
457
 Send a HTTP request uses given headers and body, and return a Promise.
461
 Send a HTTP request uses given headers and body, and return a Promise.
468
 
472
 
469
 #### `fetch(...).progress(eventListener):Promise<FetchBlobResponse>`
473
 #### `fetch(...).progress(eventListener):Promise<FetchBlobResponse>`
470
 
474
 
475
+---
476
+
471
 `0.4.2`
477
 `0.4.2`
472
 
478
 
473
 Register on progress event handler for a fetch request.
479
 Register on progress event handler for a fetch request.
482
 
488
 
483
 #### `base64`
489
 #### `base64`
484
 
490
 
491
+---
492
+
485
 `0.4.2`
493
 `0.4.2`
486
 
494
 
487
 A helper object simply uses [base-64](https://github.com/mathiasbynens/base64) for decode and encode BASE64 data.
495
 A helper object simply uses [base-64](https://github.com/mathiasbynens/base64) for decode and encode BASE64 data.
493
 
501
 
494
 #### `fs`
502
 #### `fs`
495
 
503
 
504
+---
505
+
496
 `0.5.0`
506
 `0.5.0`
497
 
507
 
498
 #### getSystemDirs():Promise<object>
508
 #### getSystemDirs():Promise<object>
499
 
509
 
500
 This method returns common used folders:
510
 This method returns common used folders:
501
-* DocumentDir 
502
-* CacheDir
503
-* DCIMDir (Android Only)
504
-* DownloadDir (Android Only)
505
-
506
-example 
511
+- DocumentDir
512
+- CacheDir
513
+- DCIMDir (Android Only)
514
+- DownloadDir (Android Only)
507
 
515
 
508
 ```js
516
 ```js
509
 RNFetchBlob.getSystemDirs().then((dirs) => {
517
 RNFetchBlob.getSystemDirs().then((dirs) => {
513
     console.log(dirs.DownloadDir)
521
     console.log(dirs.DownloadDir)
514
 })
522
 })
515
 ```
523
 ```
516
-
517
-If you're going to make downloaded file visible in Android `Downloads` app, please see [Show Downloaded File and Notification in Android Downloads App](#user-content-show-downloaded-file-in-android-downloads-app).
524
+If you're going to make downloaded file visible in Android `Downloads` app, please see [Show Downloaded File and Notification in Android Downloads App](#user-content-show-downloaded-file-and-notifiction-in-android-downloads-app).
518
 
525
 
519
 #### createFile(path, data, encoding):Promise
526
 #### createFile(path, data, encoding):Promise
520
 
527
 
544
 #### append:`boolean`(optional, default to `false`)
551
 #### append:`boolean`(optional, default to `false`)
545
 Will new data append after existing file or not.
552
 Will new data append after existing file or not.
546
 
553
 
547
-Calling `writeStream` method will returns a Promise, which resolves a `RNFetchBlobWriteSteam` instance when stream opened successfully. 
554
+Calling `writeStream` method will returns a Promise, which resolves a `RNFetchBlobWriteSteam` instance when stream opened successfully.
548
 
555
 
549
 ```js
556
 ```js
550
 // write utf8 data
557
 // write utf8 data
568
         stream.write(RNFetchBlob.base64.encode('foo'))
575
         stream.write(RNFetchBlob.base64.encode('foo'))
569
         return stream.close()
576
         return stream.close()
570
     })
577
     })
571
-    
578
+
572
 ```
579
 ```
573
 
580
 
574
 #### readStream(path, encoding, bufferSize):Promise<ReadStream>
581
 #### readStream(path, encoding, bufferSize):Promise<ReadStream>
583
 `readStream` returns a promise which will resolve `RNFetchBlobReadStream`.
590
 `readStream` returns a promise which will resolve `RNFetchBlobReadStream`.
584
 
591
 
585
 ```js
592
 ```js
586
-// read using `utf8` 
587
 RNFetchBlob.fs.readStream(PATH_TO_READ, 'utf8')
593
 RNFetchBlob.fs.readStream(PATH_TO_READ, 'utf8')
588
     .then((stream) => {
594
     .then((stream) => {
589
         let data = ''
595
         let data = ''
595
             console.log(data)
601
             console.log(data)
596
         })
602
         })
597
     })
603
     })
598
-// read using `ascii` 
599
-RNFetchBlob.fs.readStream(PATH_TO_READ, 'ascii')
600
-    .then((stream) => {
601
-        let data = []
602
-        stream.open()
603
-        stream.onData((chunk) => {
604
-            data = data.concat(data)
605
-        })
606
-        stream.onEnd(() => {
607
-            console.log(data)
608
-        })
609
-    })
610
-// read using `base64` 
611
-RNFetchBlob.fs.readStream(PATH_TO_READ, 'base64')
612
-    .then((stream) => {
613
-        let data = ''
614
-        stream.open()
615
-        stream.onData((chunk) => {
616
-            data += chunk
617
-        })
618
-        stream.onEnd(() => {
619
-            console.log(data)
620
-        })
621
-    })
622
 ```
604
 ```
623
 
605
 
624
 #### mkdir(path:string):Promise
606
 #### mkdir(path:string):Promise
669
 
651
 
670
 ```js
652
 ```js
671
 RNFetchBlob.fs.exists(PATH_OF_FILE)
653
 RNFetchBlob.fs.exists(PATH_OF_FILE)
672
-.then((exist) => { 
654
+.then((exist) => {
673
     console.log(`file ${exist ? '' : 'not'} exists`)
655
     console.log(`file ${exist ? '' : 'not'} exists`)
674
 })
656
 })
675
 .catch(() => { ... })
657
 .catch(() => { ... })
681
 
663
 
682
 ```js
664
 ```js
683
 RNFetchBlob.fs.exists(PATH_OF_FILE)
665
 RNFetchBlob.fs.exists(PATH_OF_FILE)
684
-.then((isDir) => { 
666
+.then((isDir) => {
685
     console.log(`file is ${isDir ? '' : 'not'} a directory`)
667
     console.log(`file is ${isDir ? '' : 'not'} a directory`)
686
 })
668
 })
687
 ```
669
 ```
715
   - mime : MIME type of the file. By default is `text/plain`
697
   - mime : MIME type of the file. By default is `text/plain`
716
   - mediaScannable : A `boolean` value, see [Officail Document](https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean))
698
   - mediaScannable : A `boolean` value, see [Officail Document](https://developer.android.com/reference/android/app/DownloadManager.html#addCompletedDownload(java.lang.String, java.lang.String, boolean, java.lang.String, java.lang.String, long, boolean))
717
   - notification : A `boolean` value decide whether show a notification when download complete.
699
   - notification : A `boolean` value decide whether show a notification when download complete.
718
-  
700
+
719
 
701
 
720
 #### RNFetchBlobResponse
702
 #### RNFetchBlobResponse
721
 
703