Ben Hsieh пре 8 година
родитељ
комит
c6007163c9
2 измењених фајлова са 80 додато и 39 уклоњено
  1. 30
    31
      src/ios/RNFetchBlobNetwork.m
  2. 50
    8
      test/test-0.10.0.js

+ 30
- 31
src/ios/RNFetchBlobNetwork.m Прегледај датотеку

@@ -515,47 +515,46 @@ NSOperationQueue *taskQueue;
515 515
     {
516 516
         errMsg = [error localizedDescription];
517 517
     }
518
-//    else
519
-//    {
520
-        if(respFile == YES)
518
+
519
+    if(respFile == YES)
520
+    {
521
+        [writeStream close];
522
+        rnfbRespType = RESP_TYPE_PATH;
523
+        respStr = destPath;
524
+    }
525
+    // base64 response
526
+    else {
527
+        // #73 fix unicode data encoding issue :
528
+        // when response type is BASE64, we should first try to encode the response data to UTF8 format
529
+        // if it turns out not to be `nil` that means the response data contains valid UTF8 string,
530
+        // in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding.
531
+        NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
532
+        
533
+        if(responseFormat == BASE64)
521 534
         {
522
-            [writeStream close];
523
-            rnfbRespType = RESP_TYPE_PATH;
524
-            respStr = destPath;
535
+            rnfbRespType = RESP_TYPE_BASE64;
536
+            respStr = [respData base64EncodedStringWithOptions:0];
525 537
         }
526
-        // base64 response
527
-        else {
528
-            // #73 fix unicode data encoding issue :
529
-            // when response type is BASE64, we should first try to encode the response data to UTF8 format
530
-            // if it turns out not to be `nil` that means the response data contains valid UTF8 string,
531
-            // in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding.
532
-            NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
533
-
534
-            if(responseFormat == BASE64)
535
-            {
536
-                rnfbRespType = RESP_TYPE_BASE64;
537
-                respStr = [respData base64EncodedStringWithOptions:0];
538
-            }
539
-            else if (responseFormat == UTF8)
538
+        else if (responseFormat == UTF8)
539
+        {
540
+            rnfbRespType = RESP_TYPE_UTF8;
541
+            respStr = utf8;
542
+        }
543
+        else
544
+        {
545
+            if(utf8 != nil)
540 546
             {
541 547
                 rnfbRespType = RESP_TYPE_UTF8;
542 548
                 respStr = utf8;
543 549
             }
544 550
             else
545 551
             {
546
-                if(utf8 != nil)
547
-                {
548
-                    rnfbRespType = RESP_TYPE_UTF8;
549
-                    respStr = utf8;
550
-                }
551
-                else
552
-                {
553
-                    rnfbRespType = RESP_TYPE_BASE64;
554
-                    respStr = [respData base64EncodedStringWithOptions:0];
555
-                }
552
+                rnfbRespType = RESP_TYPE_BASE64;
553
+                respStr = [respData base64EncodedStringWithOptions:0];
556 554
             }
557 555
         }
558
-//    }
556
+        }
557
+
559 558
 
560 559
     callback(@[ errMsg, rnfbRespType, respStr]);
561 560
 

+ 50
- 8
test/test-0.10.0.js Прегледај датотеку

@@ -13,8 +13,10 @@ import {
13 13
   AsyncStorage,
14 14
   Image,
15 15
 } from 'react-native';
16
+
16 17
 window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest
17 18
 window.Blob = RNFetchBlob.polyfill.Blob
19
+
18 20
 const JSONStream = RNFetchBlob.JSONStream
19 21
 const fs = RNFetchBlob.fs
20 22
 const { Assert, Comparer, Info, prop } = RNTest
@@ -99,11 +101,17 @@ describe('SSL test #159', (report, done) => {
99 101
       'Cache-Control' : 'no-store'
100 102
     })
101 103
     .then(res => {
102
-      report(<Assert key="trusty request should pass" expect={true} actual={true}/>)
104
+      report(<Assert
105
+        key="trusty request should pass"
106
+        expect={true}
107
+        actual={true}/>)
103 108
       return RNFetchBlob.fetch('GET',`${TEST_SERVER_URL_SSL}/public/github.png`)
104 109
     })
105 110
     .catch(e => {
106
-      report(<Assert key="non-trusty request should not pass" expect={true} actual={true}/>)
111
+      report(<Assert
112
+        key="non-trusty request should not pass"
113
+        expect={true}
114
+        actual={true}/>)
107 115
       done()
108 116
     })
109 117
 })
@@ -118,11 +126,18 @@ describe('#171 appendExt verify', (report, done) => {
118 126
     'Cache-Control' : 'no-store'
119 127
   })
120 128
   .then(res => {
121
-    report(<Assert key="extension appended to tmp path" actual={/.png$/.test(res.path())} expect={true}/>)
129
+    console.log(res.path())
130
+    report(<Assert
131
+      key="extension appended to tmp path"
132
+      actual={/.png$/.test(res.path())}
133
+      expect={true}/>)
122 134
     return fs.stat(res.path())
123 135
   })
124 136
   .then(stat => {
125
-    report(<Assert key="verify the file existence" expect="23975" actual={stat.size} />)
137
+    report(<Assert
138
+      key="verify the file existence"
139
+      expect="23975"
140
+      actual={stat.size} />)
126 141
     done()
127 142
   })
128 143
 
@@ -137,7 +152,10 @@ describe('#173 issue with append option', (report, done) => {
137 152
   .fetch('GET', `${TEST_SERVER_URL}/public/github.png`)
138 153
   .then((res) => fs.stat(res.path()))
139 154
   .then((stat) => {
140
-    report(<Assert key="file size check #1" expect="23975" actual={stat.size}/>)
155
+    report(<Assert
156
+      key="file size check #1"
157
+      expect="23975"
158
+      actual={stat.size}/>)
141 159
     return RNFetchBlob.config({
142 160
       path : dest,
143 161
       overwrite : false
@@ -146,7 +164,10 @@ describe('#173 issue with append option', (report, done) => {
146 164
   })
147 165
   .then((res) => fs.stat(res.path()))
148 166
   .then((stat) => {
149
-    report(<Assert key="file size check #2" expect="47950" actual={stat.size}/>)
167
+    report(<Assert
168
+      key="file size check #2"
169
+      expect="47950"
170
+      actual={stat.size}/>)
150 171
     return RNFetchBlob.config({
151 172
       path : dest,
152 173
       overwrite : true
@@ -155,7 +176,10 @@ describe('#173 issue with append option', (report, done) => {
155 176
   })
156 177
   .then((res) => fs.stat(res.path()))
157 178
   .then((stat) => {
158
-    report(<Assert key="file size check #3" expect="23975" actual={stat.size}/>)
179
+    report(<Assert
180
+      key="file size check #3"
181
+      expect="23975"
182
+      actual={stat.size}/>)
159 183
     return RNFetchBlob.config({
160 184
       path : dest,
161 185
     })
@@ -163,10 +187,28 @@ describe('#173 issue with append option', (report, done) => {
163 187
   })
164 188
   .then((res) => fs.stat(res.path()))
165 189
   .then((stat) => {
166
-    report(<Assert key="it should successfully overwrite existing file without config"
190
+    report(<Assert
191
+      key="it should successfully overwrite existing file without config"
167 192
       expect="23975"
168 193
       actual={stat.size}/>)
169 194
     done()
170 195
   })
171 196
 
172 197
 })
198
+
199
+describe('#171 verification ', (report, done) => {
200
+
201
+  RNFetchBlob
202
+    .config({
203
+      session: 'SESSION_NAME',
204
+      fileCache: true,
205
+      appendExt: 'mp4'
206
+    })
207
+    .fetch('GET', `${TEST_SERVER_URL}/public/cat-fu.mp4`)
208
+    .then(res => {
209
+      console.log(res.path())
210
+    })
211
+
212
+
213
+
214
+})