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

Commit f7a007a

Browse files
committed
Merge branch '0.10.2' of github.com:wkh237/react-native-fetch-blob into 0.10.2
2 parents 1b4f4bf + 40d7862 commit f7a007a

File tree

5 files changed

+60
-51
lines changed

5 files changed

+60
-51
lines changed

src/ios/RNFetchBlobFS.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define RNFetchBlobFS_h
1111

1212
#import "RNFetchBlob.h"
13-
1413
#import <Foundation/Foundation.h>
1514

1615
#if __has_include(<React/RCTAssert.h>)

src/ios/RNFetchBlobFS.m

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ - (id)initWithBridgeRef:(RCTBridge *)bridgeRef {
6464

6565
// static member getter
6666
+ (NSArray *) getFileStreams {
67-
67+
6868
if(fileStreams == nil)
6969
fileStreams = [[NSMutableDictionary alloc] init];
7070
return fileStreams;
@@ -115,12 +115,12 @@ + (NSString *) getPictureDir {
115115
}
116116

117117
+ (NSString *) getTempPath {
118-
118+
119119
return NSTemporaryDirectory();
120120
}
121121

122122
+ (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext {
123-
123+
124124
NSString * documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
125125
NSString * filename = [NSString stringWithFormat:@"/RNFetchBlob_tmp/RNFetchBlobTmp_%@", taskId];
126126
if(ext != nil)
@@ -129,7 +129,7 @@ + (NSString *) getTempPath:(NSString*)taskId withExtension:(NSString *)ext {
129129
return tempPath;
130130
}
131131

132-
#pragma margk - readStream
132+
#pragma margk - readStream
133133

134134
+ (void) readStream:(NSString *)uri
135135
encoding:(NSString * )encoding
@@ -139,7 +139,7 @@ + (void) readStream:(NSString *)uri
139139
bridgeRef:(RCTBridge *)bridgeRef
140140
{
141141
[[self class] getPathFromUri:uri completionHandler:^(NSString *path, ALAssetRepresentation *asset) {
142-
142+
143143
__block RCTEventDispatcher * event = bridgeRef.eventDispatcher;
144144
__block int read = 0;
145145
__block int backoff = tick *1000;
@@ -193,7 +193,7 @@ + (void) readStream:(NSString *)uri
193193
// release buffer
194194
if(buffer != nil)
195195
free(buffer);
196-
196+
197197
}
198198
@catch (NSError * err)
199199
{
@@ -205,10 +205,10 @@ + (void) readStream:(NSString *)uri
205205
NSDictionary * payload = @{ @"event": FS_EVENT_END, @"detail": @"" };
206206
[event sendDeviceEventWithName:streamId body:payload];
207207
}
208-
208+
209209
}];
210-
211-
210+
211+
212212
}
213213

214214
// send read stream chunks via native event emitter
@@ -243,8 +243,8 @@ + (void) emitDataChunks:(NSData *)data encoding:(NSString *) encoding streamId:(
243243
NSDictionary * payload = @{ @"event": FS_EVENT_DATA, @"detail" : asciiArray };
244244
[event sendDeviceEventWithName:streamId body:payload];
245245
}
246-
247-
246+
247+
248248
}
249249

250250
# pragma write file from file
@@ -274,7 +274,7 @@ + (NSNumber *) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:
274274
}
275275
else if(asset != nil)
276276
{
277-
277+
278278
__block NSOutputStream * os = [[NSOutputStream alloc] initToFileAtPath:dest append:append];
279279
int read = 0;
280280
int cursor = 0;
@@ -293,7 +293,7 @@ + (NSNumber *) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:
293293
else
294294
callback(@"failed to resolve path", nil);
295295
}];
296-
296+
297297
return 0;
298298
}
299299

@@ -342,7 +342,7 @@ + (void) writeFile:(NSString *)path encoding:(NSString *)encoding data:(NSString
342342
[content writeToFile:path atomically:YES];
343343
}
344344
fm = nil;
345-
345+
346346
resolve([NSNumber numberWithInteger:[content length]]);
347347
}
348348
@catch (NSException * e)
@@ -423,16 +423,16 @@ + (void) readFile:(NSString *)path encoding:(NSString *)encoding
423423
else
424424
{
425425
if(![[NSFileManager defaultManager] fileExistsAtPath:path]) {
426-
426+
427427
reject(@"RNFetchBlobFS readFile error", @"file not exists", nil);
428428
return;
429429
}
430430
fileContent = [NSData dataWithContentsOfFile:path];
431-
431+
432432
}
433433
if(onComplete != nil)
434434
onComplete(fileContent);
435-
435+
436436
if([[encoding lowercaseString] isEqualToString:@"utf8"]) {
437437
if(resolve != nil) {
438438
NSString * utf8 = [[NSString alloc] initWithData:fileContent encoding:NSUTF8StringEncoding];
@@ -480,7 +480,7 @@ + (BOOL) mkdir:(NSString *) path {
480480

481481
+ (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
482482

483-
483+
484484
BOOL isDir = NO;
485485
NSFileManager * fm = [NSFileManager defaultManager];
486486
if([fm fileExistsAtPath:path isDirectory:&isDir] == NO) {
@@ -498,7 +498,7 @@ + (NSDictionary *) stat:(NSString *) path error:(NSError **) error {
498498
@"lastModified" : [NSNumber numberWithLong:(time_t) [lastModified timeIntervalSince1970]*1000],
499499
@"type" : isDir ? @"directory" : @"file"
500500
};
501-
501+
502502
}
503503

504504
# pragma mark - exists
@@ -584,7 +584,7 @@ - (void)closeOutStream {
584584
[self.outStream close];
585585
self.outStream = nil;
586586
}
587-
587+
588588
}
589589

590590
// Slice a file into another file, generally for support Blob implementation.
@@ -614,14 +614,14 @@ + (void)slice:(NSString *)path
614614
}
615615
long size = [fm attributesOfItemAtPath:path error:nil].fileSize;
616616
long max = MIN(size, [end longValue]);
617-
617+
618618
if(![fm fileExistsAtPath:dest]) {
619619
[fm createFileAtPath:dest contents:@"" attributes:nil];
620620
}
621621
[handle seekToFileOffset:[start longValue]];
622622
while(read < expected)
623623
{
624-
624+
625625
NSData * chunk;
626626
long chunkSize = 0;
627627
if([start longValue] + read + 10240 > max)
@@ -639,7 +639,7 @@ + (void)slice:(NSString *)path
639639
if([chunk length] <= 0)
640640
break;
641641
long remain = expected - read;
642-
642+
643643
[os write:[chunk bytes] maxLength:chunkSize];
644644
read += [chunk length];
645645
}
@@ -656,10 +656,10 @@ + (void)slice:(NSString *)path
656656
[os open];
657657
long size = asset.size;
658658
long max = MIN(size, [end longValue]);
659-
659+
660660
while(read < expected)
661661
{
662-
662+
663663
uint8_t * chunk[10240];
664664
long chunkSize = 0;
665665
if([start longValue] + read + 10240 > max)
@@ -677,7 +677,7 @@ + (void)slice:(NSString *)path
677677
if( chunkRead <= 0)
678678
break;
679679
long remain = expected - read;
680-
680+
681681
[os write:chunk maxLength:chunkSize];
682682
read += chunkRead;
683683
}
@@ -688,7 +688,7 @@ + (void)slice:(NSString *)path
688688
{
689689
reject(@"slice error", [NSString stringWithFormat: @"could not resolve URI %@", path ], nil);
690690
}
691-
691+
692692
}];
693693
}
694694

@@ -701,7 +701,7 @@ - (void)closeInStream
701701
[[RNFetchBlobFS getFileStreams] setValue:nil forKey:self.streamId];
702702
self.streamId = nil;
703703
}
704-
704+
705705
}
706706

707707

@@ -737,7 +737,7 @@ +(void) df:(RCTResponseSenderBlock)callback
737737
NSError *error = nil;
738738
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
739739
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
740-
740+
741741
if (dictionary) {
742742
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
743743
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
@@ -750,7 +750,7 @@ +(void) df:(RCTResponseSenderBlock)callback
750750
} else {
751751
callback(@[@"failed to get storage usage."]);
752752
}
753-
753+
754754
}
755755

756756
+ (void) writeAssetToPath:(ALAssetRepresentation * )rep dest:(NSString *)dest

src/ios/RNFetchBlobNetwork.m

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ + (NSArray *) getCookies:(NSString *) url
127127
[cookieStr appendString:cookie.name];
128128
[cookieStr appendString:@"="];
129129
[cookieStr appendString:cookie.value];
130-
130+
131131
if(cookie.expiresDate == nil) {
132132
[cookieStr appendString:@"; max-age=0"];
133133
}
@@ -138,18 +138,18 @@ + (NSArray *) getCookies:(NSString *) url
138138
NSString *strDate = [dateFormatter stringFromDate:cookie.expiresDate];
139139
[cookieStr appendString:strDate];
140140
}
141-
142-
141+
142+
143143
[cookieStr appendString:@"; domain="];
144144
[cookieStr appendString:hostname];
145145
[cookieStr appendString:@"; path="];
146146
[cookieStr appendString:cookie.path];
147-
148-
147+
148+
149149
if (cookie.isSecure) {
150150
[cookieStr appendString:@"; secure"];
151151
}
152-
152+
153153
if (cookie.isHTTPOnly) {
154154
[cookieStr appendString:@"; httponly"];
155155
}
@@ -284,7 +284,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
284284
respData = [[NSMutableData alloc] init];
285285
respFile = NO;
286286
}
287-
287+
288288
__block NSURLSessionDataTask * task = [session dataTaskWithRequest:req];
289289
[taskTable setObject:task forKey:taskId];
290290
[task resume];
@@ -293,7 +293,7 @@ - (void) sendRequest:(__weak NSDictionary * _Nullable )options
293293
if([[options objectForKey:CONFIG_INDICATOR] boolValue] == YES)
294294
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
295295
__block UIApplication * app = [UIApplication sharedApplication];
296-
296+
297297
// #115 handling task expired when application entering backgound for a long time
298298
UIBackgroundTaskIdentifier tid = [app beginBackgroundTaskWithName:taskId expirationHandler:^{
299299
NSLog([NSString stringWithFormat:@"session %@ expired", taskId ]);
@@ -316,7 +316,7 @@ + (void) emitExpiredTasks
316316
[bridge.eventDispatcher sendDeviceEventWithName:EVENT_EXPIRE body:args];
317317

318318
}
319-
319+
320320
// clear expired task entries
321321
[expirationTable removeAllObjects];
322322
expirationTable = [[NSMapTable alloc] init];
@@ -422,7 +422,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
422422
[cookiesTable setObject:cookies forKey:response.URL.host];
423423
}
424424
}
425-
425+
426426
[self.bridge.eventDispatcher
427427
sendDeviceEventWithName: EVENT_STATE_CHANGE
428428
body:respInfo
@@ -445,7 +445,7 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
445445
}
446446
BOOL overwrite = [options valueForKey:@"overwrite"] == nil ? YES : [[options valueForKey:@"overwrite"] boolValue];
447447
BOOL appendToExistingFile = [destPath RNFBContainsString:@"?append=true"];
448-
448+
449449
appendToExistingFile = !overwrite;
450450

451451
// For solving #141 append response data if the file already exists
@@ -559,7 +559,7 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
559559
// if it turns out not to be `nil` that means the response data contains valid UTF8 string,
560560
// in order to properly encode the UTF8 string, use URL encoding before BASE64 encoding.
561561
NSString * utf8 = [[NSString alloc] initWithData:respData encoding:NSUTF8StringEncoding];
562-
562+
563563
if(responseFormat == BASE64)
564564
{
565565
rnfbRespType = RESP_TYPE_BASE64;
@@ -652,7 +652,7 @@ - (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)sessio
652652

653653
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task willPerformHTTPRedirection:(NSHTTPURLResponse *)response newRequest:(NSURLRequest *)request completionHandler:(void (^)(NSURLRequest * _Nullable))completionHandler
654654
{
655-
655+
656656
if(followRedirect)
657657
{
658658
if(request.URL != nil)

src/ios/RNFetchBlobReqBuilder.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ +(void) buildMultipartRequest:(NSDictionary *)options
3939
{
4040
// NSString * encodedUrl = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
4141
NSString * encodedUrl = url;
42-
42+
4343
// send request
4444
__block NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString: encodedUrl]];
4545
__block NSMutableDictionary *mheaders = [[NSMutableDictionary alloc] initWithDictionary:[RNFetchBlobNetwork normalizeHeaders:headers]];
@@ -102,7 +102,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
102102
{
103103
[mheaders setValue:@"application/octet-stream" forKey:@"Content-Type"];
104104
}
105-
105+
106106
// when body is a string contains file path prefix, try load file from the path
107107
if([body hasPrefix:FILE_PREFIX]) {
108108
__block NSString * orgPath = [body substringFromIndex:[FILE_PREFIX length]];
@@ -130,7 +130,7 @@ +(void) buildOctetRequest:(NSDictionary *)options
130130
}
131131
// otherwise convert it as BASE64 data string
132132
else {
133-
133+
134134
__block NSString * cType = [[self class]getHeaderIgnoreCases:@"content-type" fromHeaders:mheaders];
135135
// when content-type is application/octet* decode body string using BASE64 decoder
136136
if([[cType lowercaseString] hasPrefix:@"application/octet"] || [[cType lowercaseString] RNFBContainsString:@";base64"])
@@ -253,14 +253,14 @@ void __block (^getFieldData)(id field) = ^(id field)
253253
}
254254

255255
+(NSString *) getHeaderIgnoreCases:(NSString *)field fromHeaders:(NSMutableDictionary *) headers {
256-
256+
257257
NSString * normalCase = [headers valueForKey:field];
258258
NSString * ignoredCase = [headers valueForKey:[field lowercaseString]];
259259
if( normalCase != nil)
260260
return normalCase;
261261
else
262262
return ignoredCase;
263-
263+
264264
}
265265

266266

0 commit comments

Comments
 (0)