Skip to content

Commit 24df33c

Browse files
committed
Merge branch 'master' into 0.5.5
2 parents 953cdab + 3045215 commit 24df33c

File tree

9 files changed

+56
-41
lines changed

9 files changed

+56
-41
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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)
22

33
A module provides upload, download, and files access API. Supports file stream read/write for process large files.
44

@@ -26,7 +26,7 @@ This update is `backward-compatible` generally you don't have to change existing
2626
* [File access](#user-content-file-access)
2727
* [File stream](#user-content-file-stream)
2828
* [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)
3030
* [API](#user-content-api)
3131
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
3232
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
@@ -847,7 +847,8 @@ A `session` is an object that helps you manage files. It simply maintains a list
847847

848848
| Version | |
849849
|---|---|
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. |
851852
| 0.5.3 | Add API for access untrusted SSL server |
852853
| 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 |
853854
| 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fetchblob",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"private": true,
55
"scripts": {
66
"start": "node node_modules/react-native/local-cli/cli.js start",

src/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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)
22

33
A module provides upload, download, and files access API. Supports file stream read/write for process large files.
44

@@ -26,7 +26,7 @@ This update is `backward-compatible` generally you don't have to change existing
2626
* [File access](#user-content-file-access)
2727
* [File stream](#user-content-file-stream)
2828
* [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)
3030
* [API](#user-content-api)
3131
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
3232
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
@@ -847,6 +847,7 @@ A `session` is an object that helps you manage files. It simply maintains a list
847847

848848
| Version | |
849849
|---|---|
850+
| 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
850851
| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
851852
| 0.5.3 | Add API for access untrusted SSL server |
852853
| 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 |

src/ios/RNFetchBlob.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
isa = XCBuildConfiguration;
234234
buildSettings = {
235235
ALWAYS_SEARCH_USER_PATHS = NO;
236+
GCC_INPUT_FILETYPE = automatic;
236237
HEADER_SEARCH_PATHS = (
237238
"$(inherited)",
238239
"$(SRCROOT)/Libraries/**",
@@ -253,6 +254,7 @@
253254
isa = XCBuildConfiguration;
254255
buildSettings = {
255256
ALWAYS_SEARCH_USER_PATHS = NO;
257+
GCC_INPUT_FILETYPE = automatic;
256258
HEADER_SEARCH_PATHS = (
257259
"$(inherited)",
258260
"$(SRCROOT)/Libraries/**",

src/ios/RNFetchBlob/RNFetchBlob.m

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ - (NSDictionary *)constantsToExport
130130
// send HTTP request
131131
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
132132
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
133+
utils = nil;
133134
});
134135
}
135136

@@ -178,6 +179,7 @@ - (NSDictionary *)constantsToExport
178179
// send HTTP request
179180
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
180181
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
182+
utils = nil;
181183
});
182184
}
183185

src/ios/RNFetchBlobFS.m

+15-10
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,18 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
258258
// read stream incoming chunk
259259
case NSStreamEventHasBytesAvailable:
260260
{
261-
NSMutableData * chunkData = [[NSMutableData data] init];
261+
NSMutableData * chunkData = [[NSMutableData alloc] init];
262262
NSInteger chunkSize = 4096;
263263
if([[self.encoding lowercaseString] isEqualToString:@"base64"])
264264
chunkSize = 4095;
265265
if(self.bufferSize > 0)
266266
chunkSize = self.bufferSize;
267-
uint8_t buf[chunkSize];
267+
uint8_t * buf = (uint8_t *)malloc(chunkSize);
268268
unsigned int len = 0;
269-
270269
len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
271270
// still have data in stream
272271
if(len) {
273-
[chunkData appendBytes:(const void *)buf length:len];
272+
[chunkData appendBytes:buf length:len];
274273
// dispatch data event
275274
NSString * encodedChunk = [NSString alloc];
276275
if( [[self.encoding lowercaseString] isEqualToString:@"utf8"] ) {
@@ -286,7 +285,6 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
286285
NSInteger byteLen = chunkData.length/sizeof(uint8_t);
287286
for (int i = 0; i < byteLen; i++)
288287
{
289-
uint8_t * byteFromArray = chunkData.bytes;
290288
NSInteger val = bytePtr[i];
291289
if(i+1 < byteLen)
292290
asciiStr = [asciiStr stringByAppendingFormat:@"%d,", val];
@@ -298,18 +296,22 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
298296
asciiStr = [asciiStr stringByAppendingString:@"]"];
299297
[self.bridge.eventDispatcher
300298
sendDeviceEventWithName:streamEventCode
301-
body:@{
302-
@"event": FS_EVENT_DATA,
303-
@"detail": asciiStr
299+
body: @{
300+
@"event": FS_EVENT_DATA,
301+
@"detail": asciiStr
304302
}
305303
];
304+
free(buf);
305+
asciiStr = nil;
306+
buf = nil;
307+
chunkData = nil;
306308
return;
307309
}
308310
// convert byte array to base64 data chunks
309311
else if ( [[self.encoding lowercaseString] isEqualToString:@"base64"] ) {
310312
encodedChunk = [chunkData base64EncodedStringWithOptions:0];
311313
}
312-
// unknown encoding, send erro event
314+
// unknown encoding, send error event
313315
else {
314316
[self.bridge.eventDispatcher
315317
sendDeviceEventWithName:streamEventCode
@@ -328,7 +330,8 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
328330
@"detail": encodedChunk
329331
}
330332
];
331-
333+
chunkData = nil;
334+
free(buf);
332335
}
333336
// end of stream
334337
else {
@@ -339,6 +342,8 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
339342
@"detail": @""
340343
}
341344
];
345+
chunkData = nil;
346+
free(buf);
342347
}
343348
break;
344349
}

src/ios/RNFetchBlobNetwork.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
2525
@property (nullable, nonatomic) RCTBridge * bridge;
2626
@property (nullable, nonatomic) NSDictionary * options;
2727
@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;
3030
@property (nullable, nonatomic) NSError * error;
3131

3232

src/ios/RNFetchBlobNetwork.m

+26-22
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ @implementation RNFetchBlobNetwork
3232
@synthesize callback;
3333
@synthesize bridge;
3434
@synthesize options;
35-
@synthesize fileTaskCompletionHandler;
36-
@synthesize dataTaskCompletionHandler;
35+
//@synthesize fileTaskCompletionHandler;
36+
//@synthesize dataTaskCompletionHandler;
3737
@synthesize error;
3838

3939

@@ -88,7 +88,8 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
8888
// file will be stored at a specific path
8989
if( path != nil) {
9090

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) {
9293
if(error != nil) {
9394
callback(@[[error localizedDescription]]);
9495
return;
@@ -102,14 +103,16 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
102103
return;
103104
}
104105
callback(@[[NSNull null], path]);
105-
};
106-
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
106+
// prevent memory leaks
107+
self.respData = nil;
108+
}];
107109
[task resume];
108110
}
109111
// file will be stored at tmp path
110112
else if ( [self.options valueForKey:CONFIG_USE_TEMP]!= nil ) {
111113

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) {
113116
if(error != nil) {
114117
callback(@[[error localizedDescription]]);
115118
return;
@@ -124,22 +127,23 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
124127
return;
125128
}
126129
callback(@[[NSNull null], tmpPath]);
127-
};
128-
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
130+
// prevent memory leaks
131+
self.respData = nil;
132+
}];
129133
[task resume];
130134
}
131135
// base64 response
132136
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) {
134139
if(error != nil) {
135140
callback(@[[error localizedDescription]]);
136141
return;
137142
}
138143
else {
139144
callback(@[[NSNull null], [resp base64EncodedStringWithOptions:0]]);
140145
}
141-
};
142-
NSURLSessionDataTask * task = [session dataTaskWithRequest:req completionHandler:dataTaskCompletionHandler];
146+
}];
143147
[task resume];
144148
}
145149
}
@@ -205,17 +209,17 @@ - (void) application:(UIApplication *)application handleEventsForBackgroundURLSe
205209

206210
}
207211

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+
//}
219223

220224
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
221225
{

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-fetch-blob",
3-
"version": "0.5.4",
3+
"version": "0.5.5",
44
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)