ソースを参照

Merge branch '0.10.2' of github.com:wkh237/react-native-fetch-blob into 0.10.2

Ben Hsieh 8 年 前
コミット
f7a007a28c
共有5 個のファイルを変更した60 個の追加51 個の削除を含む
  1. 0
    1
      src/ios/RNFetchBlobFS.h
  2. 30
    30
      src/ios/RNFetchBlobFS.m
  3. 13
    13
      src/ios/RNFetchBlobNetwork.m
  4. 5
    5
      src/ios/RNFetchBlobReqBuilder.m
  5. 12
    2
      test/test-0.10.2.js

+ 0
- 1
src/ios/RNFetchBlobFS.h ファイルの表示

@@ -10,7 +10,6 @@
10 10
 #define RNFetchBlobFS_h
11 11
 
12 12
 #import "RNFetchBlob.h"
13
-
14 13
 #import <Foundation/Foundation.h>
15 14
 
16 15
 #if __has_include(<React/RCTAssert.h>)

+ 30
- 30
src/ios/RNFetchBlobFS.m ファイルの表示

@@ -64,7 +64,7 @@ NSMutableDictionary *fileStreams = nil;
64 64
 
65 65
 // static member getter
66 66
 + (NSArray *) getFileStreams {
67
-    
67
+
68 68
     if(fileStreams == nil)
69 69
         fileStreams = [[NSMutableDictionary alloc] init];
70 70
     return fileStreams;
@@ -115,12 +115,12 @@ NSMutableDictionary *fileStreams = nil;
115 115
 }
116 116
 
117 117
 + (NSString *) getTempPath {
118
-    
118
+
119 119
     return NSTemporaryDirectory();
120 120
 }
121 121
 
122 122
 + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext {
123
-    
123
+
124 124
     NSString * documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
125 125
     NSString * filename = [NSString stringWithFormat:@"/RNFetchBlob_tmp/RNFetchBlobTmp_%@", taskId];
126 126
     if(ext != nil)
@@ -129,7 +129,7 @@ NSMutableDictionary *fileStreams = nil;
129 129
     return tempPath;
130 130
 }
131 131
 
132
-#pragma margk - readStream 
132
+#pragma margk - readStream
133 133
 
134 134
 + (void) readStream:(NSString *)uri
135 135
            encoding:(NSString * )encoding
@@ -139,7 +139,7 @@ NSMutableDictionary *fileStreams = nil;
139 139
           bridgeRef:(RCTBridge *)bridgeRef
140 140
 {
141 141
     [[self class] getPathFromUri:uri completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
142
-    
142
+
143 143
         __block RCTEventDispatcher * event = bridgeRef.eventDispatcher;
144 144
         __block int read = 0;
145 145
         __block int backoff = tick *1000;
@@ -193,7 +193,7 @@ NSMutableDictionary *fileStreams = nil;
193 193
             // release buffer
194 194
             if(buffer != nil)
195 195
                 free(buffer);
196
-            
196
+
197 197
         }
198 198
         @catch (NSError * err)
199 199
         {
@@ -205,10 +205,10 @@ NSMutableDictionary *fileStreams = nil;
205 205
             NSDictionary * payload = @{ @"event": FS_EVENT_END, @"detail": @"" };
206 206
             [event sendDeviceEventWithName:streamId body:payload];
207 207
         }
208
-        
208
+
209 209
     }];
210
-    
211
-    
210
+
211
+
212 212
 }
213 213
 
214 214
 // send read stream chunks via native event emitter
@@ -243,8 +243,8 @@ NSMutableDictionary *fileStreams = nil;
243 243
         NSDictionary * payload = @{ @"event": FS_EVENT_DATA,  @"detail" : asciiArray };
244 244
         [event sendDeviceEventWithName:streamId body:payload];
245 245
     }
246
-    
247
-    
246
+
247
+
248 248
 }
249 249
 
250 250
 # pragma write file from file
@@ -274,7 +274,7 @@ NSMutableDictionary *fileStreams = nil;
274 274
         }
275 275
         else if(asset != nil)
276 276
         {
277
-            
277
+
278 278
             __block NSOutputStream * os = [[NSOutputStream alloc] initToFileAtPath:dest append:append];
279 279
             int read = 0;
280 280
             int cursor = 0;
@@ -293,7 +293,7 @@ NSMutableDictionary *fileStreams = nil;
293 293
         else
294 294
             callback(@"failed to resolve path", nil);
295 295
     }];
296
-    
296
+
297 297
     return 0;
298 298
 }
299 299
 
@@ -342,7 +342,7 @@ NSMutableDictionary *fileStreams = nil;
342 342
             [content writeToFile:path atomically:YES];
343 343
         }
344 344
         fm = nil;
345
-        
345
+
346 346
         resolve([NSNumber numberWithInteger:[content length]]);
347 347
     }
348 348
     @catch (NSException * e)
@@ -423,16 +423,16 @@ NSMutableDictionary *fileStreams = nil;
423 423
             else
424 424
             {
425 425
                 if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {
426
-                    
426
+
427 427
                     reject(@"RNFetchBlobFS readFile error", @"file not exists", nil);
428 428
                     return;
429 429
                 }
430 430
                 fileContent = [NSData dataWithContentsOfFile:path];
431
-                
431
+
432 432
             }
433 433
             if(onComplete != nil)
434 434
                 onComplete(fileContent);
435
-            
435
+
436 436
             if([[encoding lowercaseString] isEqualToString:@"utf8"]) {
437 437
                 if(resolve != nil) {
438 438
                     NSString * utf8 = [[NSString alloc] initWithData:fileContent encoding:NSUTF8StringEncoding];
@@ -480,7 +480,7 @@ NSMutableDictionary *fileStreams = nil;
480 480
 
481 481
 + (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
482 482
 
483
-    
483
+
484 484
     BOOL isDir = NO;
485 485
     NSFileManager * fm = [NSFileManager defaultManager];
486 486
     if([fm fileExistsAtPath:path isDirectory:&isDir] == NO) {
@@ -498,7 +498,7 @@ NSMutableDictionary *fileStreams = nil;
498 498
              @"lastModified" : [NSNumber numberWithLong:(time_t) [lastModified timeIntervalSince1970]*1000],
499 499
              @"type" : isDir ? @"directory" : @"file"
500 500
             };
501
-    
501
+
502 502
 }
503 503
 
504 504
 # pragma mark - exists
@@ -584,7 +584,7 @@ NSMutableDictionary *fileStreams = nil;
584 584
         [self.outStream close];
585 585
         self.outStream = nil;
586 586
     }
587
-    
587
+
588 588
 }
589 589
 
590 590
 // Slice a file into another file, generally for support Blob implementation.
@@ -614,14 +614,14 @@ NSMutableDictionary *fileStreams = nil;
614 614
             }
615 615
             long size = [fm attributesOfItemAtPath:path error:nil].fileSize;
616 616
             long max = MIN(size, [end longValue]);
617
-            
617
+
618 618
             if(![fm fileExistsAtPath:dest]) {
619 619
                 [fm createFileAtPath:dest contents:@"" attributes:nil];
620 620
             }
621 621
             [handle seekToFileOffset:[start longValue]];
622 622
             while(read < expected)
623 623
             {
624
-                
624
+
625 625
                 NSData * chunk;
626 626
                 long chunkSize = 0;
627 627
                 if([start longValue] + read + 10240 > max)
@@ -639,7 +639,7 @@ NSMutableDictionary *fileStreams = nil;
639 639
                 if([chunk length] <= 0)
640 640
                     break;
641 641
                 long remain = expected - read;
642
-                
642
+
643 643
                 [os write:[chunk bytes] maxLength:chunkSize];
644 644
                 read += [chunk length];
645 645
             }
@@ -656,10 +656,10 @@ NSMutableDictionary *fileStreams = nil;
656 656
             [os open];
657 657
             long size = asset.size;
658 658
             long max = MIN(size, [end longValue]);
659
-            
659
+
660 660
             while(read < expected)
661 661
             {
662
-                
662
+
663 663
                 uint8_t * chunk[10240];
664 664
                 long chunkSize = 0;
665 665
                 if([start longValue] + read + 10240 > max)
@@ -677,7 +677,7 @@ NSMutableDictionary *fileStreams = nil;
677 677
                 if( chunkRead <= 0)
678 678
                     break;
679 679
                 long remain = expected - read;
680
-                
680
+
681 681
                 [os write:chunk maxLength:chunkSize];
682 682
                 read += chunkRead;
683 683
             }
@@ -688,7 +688,7 @@ NSMutableDictionary *fileStreams = nil;
688 688
         {
689 689
             reject(@"slice error",  [NSString stringWithFormat: @"could not resolve URI %@", path ], nil);
690 690
         }
691
-        
691
+
692 692
     }];
693 693
 }
694 694
 
@@ -701,7 +701,7 @@ NSMutableDictionary *fileStreams = nil;
701 701
         [[RNFetchBlobFS getFileStreams] setValue:nil forKey:self.streamId];
702 702
         self.streamId = nil;
703 703
     }
704
-    
704
+
705 705
 }
706 706
 
707 707
 
@@ -737,7 +737,7 @@ NSMutableDictionary *fileStreams = nil;
737 737
     NSError *error = nil;
738 738
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
739 739
     NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
740
-    
740
+
741 741
     if (dictionary) {
742 742
         NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
743 743
         NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
@@ -750,7 +750,7 @@ NSMutableDictionary *fileStreams = nil;
750 750
     } else {
751 751
         callback(@[@"failed to get storage usage."]);
752 752
     }
753
-    
753
+
754 754
 }
755 755
 
756 756
 + (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest

+ 13
- 13
src/ios/RNFetchBlobNetwork.m ファイルの表示

@@ -127,7 +127,7 @@ NSOperationQueue *taskQueue;
127 127
         [cookieStr appendString:cookie.name];
128 128
         [cookieStr appendString:@"="];
129 129
         [cookieStr appendString:cookie.value];
130
-        
130
+
131 131
         if(cookie.expiresDate == nil) {
132 132
             [cookieStr appendString:@"; max-age=0"];
133 133
         }
@@ -138,18 +138,18 @@ NSOperationQueue *taskQueue;
138 138
             NSString *strDate = [dateFormatter stringFromDate:cookie.expiresDate];
139 139
             [cookieStr appendString:strDate];
140 140
         }
141
-        
142
-        
141
+
142
+
143 143
         [cookieStr appendString:@"; domain="];
144 144
         [cookieStr appendString:hostname];
145 145
         [cookieStr appendString:@"; path="];
146 146
         [cookieStr appendString:cookie.path];
147
-        
148
-        
147
+
148
+
149 149
         if (cookie.isSecure) {
150 150
             [cookieStr appendString:@"; secure"];
151 151
         }
152
-        
152
+
153 153
         if (cookie.isHTTPOnly) {
154 154
             [cookieStr appendString:@"; httponly"];
155 155
         }
@@ -284,7 +284,7 @@ NSOperationQueue *taskQueue;
284 284
         respData = [[NSMutableData alloc] init];
285 285
         respFile = NO;
286 286
     }
287
-    
287
+
288 288
     __block NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
289 289
     [taskTable setObject:task forKey:taskId];
290 290
     [task resume];
@@ -293,7 +293,7 @@ NSOperationQueue *taskQueue;
293 293
     if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
294 294
         [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
295 295
     __block UIApplication * app = [UIApplication sharedApplication];
296
-    
296
+
297 297
     // #115 handling task expired when application entering backgound for a long time
298 298
     UIBackgroundTaskIdentifier tid = [app beginBackgroundTaskWithName:taskId expirationHandler:^{
299 299
         NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
@@ -316,7 +316,7 @@ NSOperationQueue *taskQueue;
316 316
         [bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
317 317
 
318 318
     }
319
-    
319
+
320 320
     // clear expired task entries
321 321
     [expirationTable removeAllObjects];
322 322
     expirationTable = [[NSMapTable alloc] init];
@@ -422,7 +422,7 @@ NSOperationQueue *taskQueue;
422 422
                 [cookiesTable setObject:cookies forKey:response.URL.host];
423 423
             }
424 424
         }
425
-        
425
+
426 426
         [self.bridge.eventDispatcher
427 427
          sendDeviceEventWithName: EVENT_STATE_CHANGE
428 428
          body:respInfo
@@ -445,7 +445,7 @@ NSOperationQueue *taskQueue;
445 445
             }
446 446
             BOOL overwrite = [options valueForKey:@"overwrite"] == nil ? YES : [[options valueForKey:@"overwrite"] boolValue];
447 447
             BOOL appendToExistingFile = [destPath RNFBContainsString:@"?append=true"];
448
-            
448
+
449 449
             appendToExistingFile = !overwrite;
450 450
 
451 451
             // For solving #141 append response data if the file already exists
@@ -559,7 +559,7 @@ NSOperationQueue *taskQueue;
559 559
         // if it turns out not to be `nil` that means the response data contains valid UTF8 string,
560 560
         // in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding.
561 561
         NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
562
-        
562
+
563 563
         if(responseFormat == BASE64)
564 564
         {
565 565
             rnfbRespType = RESP_TYPE_BASE64;
@@ -652,7 +652,7 @@ NSOperationQueue *taskQueue;
652 652
 
653 653
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler
654 654
 {
655
-    
655
+
656 656
     if(followRedirect)
657 657
     {
658 658
         if(request.URL != nil)

+ 5
- 5
src/ios/RNFetchBlobReqBuilder.m ファイルの表示

@@ -39,7 +39,7 @@
39 39
 {
40 40
     //    NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
41 41
     NSString * encodedUrl = url;
42
-    
42
+
43 43
     // send request
44 44
     __block NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: encodedUrl]];
45 45
     __block NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
@@ -102,7 +102,7 @@
102 102
                 {
103 103
                     [mheaders setValue:@"application/octet-stream" forKey:@"Content-Type"];
104 104
                 }
105
-                
105
+
106 106
                 // when body is a string contains file path prefix, try load file from the path
107 107
                 if([body hasPrefix:FILE_PREFIX]) {
108 108
                     __block NSString * orgPath = [body substringFromIndex:[FILE_PREFIX length]];
@@ -130,7 +130,7 @@
130 130
                 }
131 131
                 // otherwise convert it as BASE64 data string
132 132
                 else {
133
-                    
133
+
134 134
                     __block NSString * cType = [[self class]getHeaderIgnoreCases:@"content-type" fromHeaders:mheaders];
135 135
                     // when content-type is application/octet* decode body string using BASE64 decoder
136 136
                     if([[cType lowercaseString] hasPrefix:@"application/octet"] || [[cType lowercaseString] RNFBContainsString:@";base64"])
@@ -253,14 +253,14 @@
253 253
 }
254 254
 
255 255
 +(NSString *) getHeaderIgnoreCases:(NSString *)field fromHeaders:(NSMutableDictionary *) headers {
256
-    
256
+
257 257
     NSString * normalCase = [headers valueForKey:field];
258 258
     NSString * ignoredCase = [headers valueForKey:[field lowercaseString]];
259 259
     if( normalCase != nil)
260 260
         return normalCase;
261 261
     else
262 262
         return ignoredCase;
263
-    
263
+
264 264
 }
265 265
 
266 266
 

+ 12
- 2
test/test-0.10.2.js ファイルの表示

@@ -43,7 +43,7 @@ describe('#227 IOS file modification date correctness', (report, done) => {
43 43
     let correct = date/Date.now() > 0.95 || date/Date.now() < 1.05;
44 44
     report(<Assert key="modification date should be correct"
45 45
       expect={true} actual={correct}/>);
46
-    done();
46
+    done()
47 47
 
48 48
   })
49 49
 
@@ -57,7 +57,17 @@ describe('#230 add and option for setting if the request follow redirect or not'
57 57
   .then((res) => {
58 58
     console.log(res.data)
59 59
     report(<Assert key="should not redirect twice" expect={1} actual={res.info().redirects.length}/>);
60
-    done();
60
+    done()
61 61
   })
62 62
 
63 63
 })
64
+
65
+describe('#241 null header silent failed issue', (report, done) => {
66
+
67
+  RNFetchBlob.fetch('GET', `${TEST_SERVER_URL}/public/github.png`, {
68
+    foo : null
69
+  })
70
+  .then(() => {
71
+    done()
72
+  })
73
+})