Ver código fonte

Merge branch 'master' into 0.5.5

Ben Hsieh 8 anos atrás
pai
commit
24df33c704

+ 4
- 3
README.md Ver arquivo

1
-# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.4-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
1
+# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.5-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
2
 
2
 
3
 A module provides upload, download, and files access API. Supports file stream read/write for process large files.
3
 A module provides upload, download, and files access API. Supports file stream read/write for process large files.
4
 
4
 
26
  * [File access](#user-content-file-access)
26
  * [File access](#user-content-file-access)
27
  * [File stream](#user-content-file-stream)
27
  * [File stream](#user-content-file-stream)
28
  * [Manage cached files](#user-content-manage-cached-files)
28
  * [Manage cached files](#user-content-manage-cached-files)
29
- * [Self-Signed SSL Server](#user-content-selfsigned-ssl-server)
29
+ * [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
30
 * [API](#user-content-api)
30
 * [API](#user-content-api)
31
  * [config](#user-content-configoptionsrnfetchblobconfigfetch)
31
  * [config](#user-content-configoptionsrnfetchblobconfigfetch)
32
  * [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
32
  * [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
847
 
847
 
848
 | Version | |
848
 | Version | |
849
 |---|---|
849
 |---|---|
850
-| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. | 
850
+| 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
851
+| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
851
 | 0.5.3 | Add API for access untrusted SSL server |
852
 | 0.5.3 | Add API for access untrusted SSL server |
852
 | 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |
853
 | 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |
853
 | 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |
854
 | 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |

+ 1
- 1
package.json Ver arquivo

1
 {
1
 {
2
   "name": "fetchblob",
2
   "name": "fetchblob",
3
-  "version": "0.5.4",
3
+  "version": "0.5.5",
4
   "private": true,
4
   "private": true,
5
   "scripts": {
5
   "scripts": {
6
     "start": "node node_modules/react-native/local-cli/cli.js start",
6
     "start": "node node_modules/react-native/local-cli/cli.js start",

+ 3
- 2
src/README.md Ver arquivo

1
-# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.4-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
1
+# react-native-fetch-blob [![npm version](https://img.shields.io/badge/npm package-0.5.5-brightgreen.svg)](https://badge.fury.io/js/react-native-fetch-blob) ![](https://img.shields.io/badge/PR-Welcome-brightgreen.svg) ![](https://img.shields.io/badge/in progress-0.6.0-yellow.svg)
2
 
2
 
3
 A module provides upload, download, and files access API. Supports file stream read/write for process large files.
3
 A module provides upload, download, and files access API. Supports file stream read/write for process large files.
4
 
4
 
26
  * [File access](#user-content-file-access)
26
  * [File access](#user-content-file-access)
27
  * [File stream](#user-content-file-stream)
27
  * [File stream](#user-content-file-stream)
28
  * [Manage cached files](#user-content-manage-cached-files)
28
  * [Manage cached files](#user-content-manage-cached-files)
29
- * [Self-Signed SSL Server](#user-content-selfsigned-ssl-server)
29
+ * [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
30
 * [API](#user-content-api)
30
 * [API](#user-content-api)
31
  * [config](#user-content-configoptionsrnfetchblobconfigfetch)
31
  * [config](#user-content-configoptionsrnfetchblobconfigfetch)
32
  * [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
32
  * [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
847
 
847
 
848
 | Version | |
848
 | Version | |
849
 |---|---|
849
 |---|---|
850
+| 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
850
 | 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
851
 | 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
851
 | 0.5.3 | Add API for access untrusted SSL server |
852
 | 0.5.3 | Add API for access untrusted SSL server |
852
 | 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |
853
 | 0.5.2 | Fix improper url params bug [#26](https://github.com/wkh237/react-native-fetch-blob/issues/26) and change IOS HTTP implementation from NSURLConnection to NSURLSession |

+ 2
- 0
src/ios/RNFetchBlob.xcodeproj/project.pbxproj Ver arquivo

233
 			isa = XCBuildConfiguration;
233
 			isa = XCBuildConfiguration;
234
 			buildSettings = {
234
 			buildSettings = {
235
 				ALWAYS_SEARCH_USER_PATHS = NO;
235
 				ALWAYS_SEARCH_USER_PATHS = NO;
236
+				GCC_INPUT_FILETYPE = automatic;
236
 				HEADER_SEARCH_PATHS = (
237
 				HEADER_SEARCH_PATHS = (
237
 					"$(inherited)",
238
 					"$(inherited)",
238
 					"$(SRCROOT)/Libraries/**",
239
 					"$(SRCROOT)/Libraries/**",
253
 			isa = XCBuildConfiguration;
254
 			isa = XCBuildConfiguration;
254
 			buildSettings = {
255
 			buildSettings = {
255
 				ALWAYS_SEARCH_USER_PATHS = NO;
256
 				ALWAYS_SEARCH_USER_PATHS = NO;
257
+				GCC_INPUT_FILETYPE = automatic;
256
 				HEADER_SEARCH_PATHS = (
258
 				HEADER_SEARCH_PATHS = (
257
 					"$(inherited)",
259
 					"$(inherited)",
258
 					"$(SRCROOT)/Libraries/**",
260
 					"$(SRCROOT)/Libraries/**",

+ 2
- 0
src/ios/RNFetchBlob/RNFetchBlob.m Ver arquivo

130
         // send HTTP request
130
         // send HTTP request
131
         RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
131
         RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
132
         [utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
132
         [utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
133
+        utils = nil;
133
     });
134
     });
134
 }
135
 }
135
 
136
 
178
         // send HTTP request
179
         // send HTTP request
179
         RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
180
         RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
180
         [utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
181
         [utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
182
+        utils = nil;
181
     });
183
     });
182
 }
184
 }
183
 
185
 

+ 15
- 10
src/ios/RNFetchBlobFS.m Ver arquivo

258
             // read stream incoming chunk
258
             // read stream incoming chunk
259
         case NSStreamEventHasBytesAvailable:
259
         case NSStreamEventHasBytesAvailable:
260
         {
260
         {
261
-            NSMutableData * chunkData = [[NSMutableData data] init];
261
+            NSMutableData * chunkData = [[NSMutableData alloc] init];
262
             NSInteger chunkSize = 4096;
262
             NSInteger chunkSize = 4096;
263
             if([[self.encoding lowercaseString] isEqualToString:@"base64"])
263
             if([[self.encoding lowercaseString] isEqualToString:@"base64"])
264
                 chunkSize = 4095;
264
                 chunkSize = 4095;
265
             if(self.bufferSize > 0)
265
             if(self.bufferSize > 0)
266
                 chunkSize = self.bufferSize;
266
                 chunkSize = self.bufferSize;
267
-            uint8_t buf[chunkSize];
267
+            uint8_t * buf = (uint8_t *)malloc(chunkSize);
268
             unsigned int len = 0;
268
             unsigned int len = 0;
269
-            
270
             len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
269
             len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
271
             // still have data in stream
270
             // still have data in stream
272
             if(len) {
271
             if(len) {
273
-                [chunkData appendBytes:(const void *)buf length:len];
272
+                [chunkData appendBytes:buf length:len];
274
                 // dispatch data event
273
                 // dispatch data event
275
                 NSString * encodedChunk = [NSString alloc];
274
                 NSString * encodedChunk = [NSString alloc];
276
                 if( [[self.encoding lowercaseString] isEqualToString:@"utf8"] ) {
275
                 if( [[self.encoding lowercaseString] isEqualToString:@"utf8"] ) {
286
                         NSInteger byteLen = chunkData.length/sizeof(uint8_t);
285
                         NSInteger byteLen = chunkData.length/sizeof(uint8_t);
287
                         for (int i = 0; i < byteLen; i++)
286
                         for (int i = 0; i < byteLen; i++)
288
                         {
287
                         {
289
-                            uint8_t * byteFromArray = chunkData.bytes;
290
                             NSInteger val = bytePtr[i];
288
                             NSInteger val = bytePtr[i];
291
                             if(i+1 < byteLen)
289
                             if(i+1 < byteLen)
292
                                 asciiStr = [asciiStr stringByAppendingFormat:@"%d,", val];
290
                                 asciiStr = [asciiStr stringByAppendingFormat:@"%d,", val];
298
                     asciiStr = [asciiStr stringByAppendingString:@"]"];
296
                     asciiStr = [asciiStr stringByAppendingString:@"]"];
299
                     [self.bridge.eventDispatcher
297
                     [self.bridge.eventDispatcher
300
                      sendDeviceEventWithName:streamEventCode
298
                      sendDeviceEventWithName:streamEventCode
301
-                     body:@{
302
-                            @"event": FS_EVENT_DATA,
303
-                            @"detail": asciiStr
299
+                     body: @{
300
+                             @"event": FS_EVENT_DATA,
301
+                             @"detail": asciiStr
304
                             }
302
                             }
305
                      ];
303
                      ];
304
+                    free(buf);
305
+                    asciiStr = nil;
306
+                    buf = nil;
307
+                    chunkData = nil;
306
                     return;
308
                     return;
307
                 }
309
                 }
308
                 // convert byte array to base64 data chunks
310
                 // convert byte array to base64 data chunks
309
                 else if ( [[self.encoding lowercaseString] isEqualToString:@"base64"] ) {
311
                 else if ( [[self.encoding lowercaseString] isEqualToString:@"base64"] ) {
310
                     encodedChunk = [chunkData base64EncodedStringWithOptions:0];
312
                     encodedChunk = [chunkData base64EncodedStringWithOptions:0];
311
                 }
313
                 }
312
-                // unknown encoding, send erro event
314
+                // unknown encoding, send error event
313
                 else {
315
                 else {
314
                     [self.bridge.eventDispatcher
316
                     [self.bridge.eventDispatcher
315
                      sendDeviceEventWithName:streamEventCode
317
                      sendDeviceEventWithName:streamEventCode
328
                         @"detail": encodedChunk
330
                         @"detail": encodedChunk
329
                         }
331
                         }
330
                  ];
332
                  ];
331
-                
333
+                chunkData = nil;
334
+                free(buf);
332
             }
335
             }
333
             // end of stream
336
             // end of stream
334
             else {
337
             else {
339
                         @"detail": @""
342
                         @"detail": @""
340
                         }
343
                         }
341
                  ];
344
                  ];
345
+                chunkData = nil;
346
+                free(buf);
342
             }
347
             }
343
             break;
348
             break;
344
         }
349
         }

+ 2
- 2
src/ios/RNFetchBlobNetwork.h Ver arquivo

25
 @property (nullable, nonatomic) RCTBridge * bridge;
25
 @property (nullable, nonatomic) RCTBridge * bridge;
26
 @property (nullable, nonatomic) NSDictionary * options;
26
 @property (nullable, nonatomic) NSDictionary * options;
27
 @property (nullable, nonatomic) RNFetchBlobFS * fileStream;
27
 @property (nullable, nonatomic) RNFetchBlobFS * fileStream;
28
-@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
29
-@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
28
+//@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
29
+//@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
30
 @property (nullable, nonatomic) NSError * error;
30
 @property (nullable, nonatomic) NSError * error;
31
 
31
 
32
 
32
 

+ 26
- 22
src/ios/RNFetchBlobNetwork.m Ver arquivo

32
 @synthesize callback;
32
 @synthesize callback;
33
 @synthesize bridge;
33
 @synthesize bridge;
34
 @synthesize options;
34
 @synthesize options;
35
-@synthesize fileTaskCompletionHandler;
36
-@synthesize dataTaskCompletionHandler;
35
+//@synthesize fileTaskCompletionHandler;
36
+//@synthesize dataTaskCompletionHandler;
37
 @synthesize error;
37
 @synthesize error;
38
 
38
 
39
 
39
 
88
     // file will be stored at a specific path
88
     // file will be stored at a specific path
89
     if( path != nil) {
89
     if( path != nil) {
90
         
90
         
91
-        self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
91
+//        self.fileTaskCompletionHandler = ;
92
+        NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
92
             if(error != nil) {
93
             if(error != nil) {
93
                 callback(@[[error localizedDescription]]);
94
                 callback(@[[error localizedDescription]]);
94
                 return;
95
                 return;
102
                 return;
103
                 return;
103
             }
104
             }
104
             callback(@[[NSNull null], path]);
105
             callback(@[[NSNull null], path]);
105
-        };
106
-        NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
106
+            // prevent memory leaks
107
+            self.respData = nil;
108
+        }];
107
         [task resume];
109
         [task resume];
108
     }
110
     }
109
     // file will be stored at tmp path
111
     // file will be stored at tmp path
110
     else if ( [self.options valueForKey:CONFIG_USE_TEMP]!= nil ) {
112
     else if ( [self.options valueForKey:CONFIG_USE_TEMP]!= nil ) {
111
         
113
         
112
-        self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
114
+//        self.fileTaskCompletionHandler;
115
+        NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
113
             if(error != nil) {
116
             if(error != nil) {
114
                 callback(@[[error localizedDescription]]);
117
                 callback(@[[error localizedDescription]]);
115
                 return;
118
                 return;
124
                 return;
127
                 return;
125
             }
128
             }
126
             callback(@[[NSNull null], tmpPath]);
129
             callback(@[[NSNull null], tmpPath]);
127
-        };
128
-        NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
130
+            // prevent memory leaks
131
+            self.respData = nil;
132
+        }];
129
         [task resume];
133
         [task resume];
130
     }
134
     }
131
     // base64 response
135
     // base64 response
132
     else {
136
     else {
133
-        self.dataTaskCompletionHandler = ^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
137
+//        self.dataTaskCompletionHandler = ;
138
+        NSURLSessionDataTask * task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
134
             if(error != nil) {
139
             if(error != nil) {
135
                 callback(@[[error localizedDescription]]);
140
                 callback(@[[error localizedDescription]]);
136
                 return;
141
                 return;
138
             else {
143
             else {
139
                 callback(@[[NSNull null], [resp base64EncodedStringWithOptions:0]]);
144
                 callback(@[[NSNull null], [resp base64EncodedStringWithOptions:0]]);
140
             }
145
             }
141
-        };
142
-        NSURLSessionDataTask * task = [session dataTaskWithRequest:req completionHandler:dataTaskCompletionHandler];
146
+        }];
143
         [task resume];
147
         [task resume];
144
     }
148
     }
145
 }
149
 }
205
     
209
     
206
 }
210
 }
207
 
211
 
208
-- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
209
-{
210
-    if(self.dataTaskCompletionHandler != nil)
211
-    {
212
-        dataTaskCompletionHandler(self.respData, nil, error);
213
-    }
214
-    else if(self.fileTaskCompletionHandler != nil)
215
-    {
216
-        fileTaskCompletionHandler(nil, nil, self.error);
217
-    }
218
-}
212
+//- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
213
+//{
214
+//    if(self.dataTaskCompletionHandler != nil)
215
+//    {
216
+//        dataTaskCompletionHandler(self.respData, nil, error);
217
+//    }
218
+//    else if(self.fileTaskCompletionHandler != nil)
219
+//    {
220
+//        fileTaskCompletionHandler(nil, nil, self.error);
221
+//    }
222
+//}
219
 
223
 
220
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
224
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
221
 {
225
 {

+ 1
- 1
src/package.json Ver arquivo

1
 {
1
 {
2
   "name": "react-native-fetch-blob",
2
   "name": "react-native-fetch-blob",
3
-  "version": "0.5.4",
3
+  "version": "0.5.5",
4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
4
   "description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
5
   "main": "index.js",
5
   "main": "index.js",
6
   "scripts": {
6
   "scripts": {