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

Commit

Permalink
Merge branch 'master' into 0.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Jun 25, 2016
2 parents 953cdab + 3045215 commit 24df33c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 41 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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)
# 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)

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

Expand Down Expand Up @@ -26,7 +26,7 @@ This update is `backward-compatible` generally you don't have to change existing
* [File access](#user-content-file-access)
* [File stream](#user-content-file-stream)
* [Manage cached files](#user-content-manage-cached-files)
* [Self-Signed SSL Server](#user-content-selfsigned-ssl-server)
* [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
* [API](#user-content-api)
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
Expand Down Expand Up @@ -847,7 +847,8 @@ A `session` is an object that helps you manage files. It simply maintains a list

| Version | |
|---|---|
| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
| 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
| 0.5.3 | Add API for access untrusted SSL server |
| 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 |
| 0.5.0 | Upload/download with direct access to file storage, and also added file access APIs |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fetchblob",
"version": "0.5.4",
"version": "0.5.5",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
Expand Down
5 changes: 3 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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)
# 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)

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

Expand Down Expand Up @@ -26,7 +26,7 @@ This update is `backward-compatible` generally you don't have to change existing
* [File access](#user-content-file-access)
* [File stream](#user-content-file-stream)
* [Manage cached files](#user-content-manage-cached-files)
* [Self-Signed SSL Server](#user-content-selfsigned-ssl-server)
* [Self-Signed SSL Server](#user-content-self-signed-ssl-server)
* [API](#user-content-api)
* [config](#user-content-configoptionsrnfetchblobconfigfetch)
* [fetch](#user-content-fetchmethod-url-headers-bodypromisefetchblobresponse)
Expand Down Expand Up @@ -847,6 +847,7 @@ A `session` is an object that helps you manage files. It simply maintains a list

| Version | |
|---|---|
| 0.5.5 | Remove work in progress code added in 0.5.2 which may cause memory leaks. |
| 0.5.4 | Fix #30 #31 build build error, and improve memory efficiency. |
| 0.5.3 | Add API for access untrusted SSL server |
| 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 |
Expand Down
2 changes: 2 additions & 0 deletions src/ios/RNFetchBlob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
GCC_INPUT_FILETYPE = automatic;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/Libraries/**",
Expand All @@ -253,6 +254,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
GCC_INPUT_FILETYPE = automatic;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(SRCROOT)/Libraries/**",
Expand Down
2 changes: 2 additions & 0 deletions src/ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ - (NSDictionary *)constantsToExport
// send HTTP request
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
utils = nil;
});
}

Expand Down Expand Up @@ -178,6 +179,7 @@ - (NSDictionary *)constantsToExport
// send HTTP request
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options bridge:self.bridge taskId:taskId withRequest:request callback:callback];
utils = nil;
});
}

Expand Down
25 changes: 15 additions & 10 deletions src/ios/RNFetchBlobFS.m
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,18 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
// read stream incoming chunk
case NSStreamEventHasBytesAvailable:
{
NSMutableData * chunkData = [[NSMutableData data] init];
NSMutableData * chunkData = [[NSMutableData alloc] init];
NSInteger chunkSize = 4096;
if([[self.encoding lowercaseString] isEqualToString:@"base64"])
chunkSize = 4095;
if(self.bufferSize > 0)
chunkSize = self.bufferSize;
uint8_t buf[chunkSize];
uint8_t * buf = (uint8_t *)malloc(chunkSize);
unsigned int len = 0;

len = [(NSInputStream *)stream read:buf maxLength:chunkSize];
// still have data in stream
if(len) {
[chunkData appendBytes:(const void *)buf length:len];
[chunkData appendBytes:buf length:len];
// dispatch data event
NSString * encodedChunk = [NSString alloc];
if( [[self.encoding lowercaseString] isEqualToString:@"utf8"] ) {
Expand All @@ -286,7 +285,6 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
NSInteger byteLen = chunkData.length/sizeof(uint8_t);
for (int i = 0; i < byteLen; i++)
{
uint8_t * byteFromArray = chunkData.bytes;
NSInteger val = bytePtr[i];
if(i+1 < byteLen)
asciiStr = [asciiStr stringByAppendingFormat:@"%d,", val];
Expand All @@ -298,18 +296,22 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
asciiStr = [asciiStr stringByAppendingString:@"]"];
[self.bridge.eventDispatcher
sendDeviceEventWithName:streamEventCode
body:@{
@"event": FS_EVENT_DATA,
@"detail": asciiStr
body: @{
@"event": FS_EVENT_DATA,
@"detail": asciiStr
}
];
free(buf);
asciiStr = nil;
buf = nil;
chunkData = nil;
return;
}
// convert byte array to base64 data chunks
else if ( [[self.encoding lowercaseString] isEqualToString:@"base64"] ) {
encodedChunk = [chunkData base64EncodedStringWithOptions:0];
}
// unknown encoding, send erro event
// unknown encoding, send error event
else {
[self.bridge.eventDispatcher
sendDeviceEventWithName:streamEventCode
Expand All @@ -328,7 +330,8 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
@"detail": encodedChunk
}
];

chunkData = nil;
free(buf);
}
// end of stream
else {
Expand All @@ -339,6 +342,8 @@ - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
@"detail": @""
}
];
chunkData = nil;
free(buf);
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ios/RNFetchBlobNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse
@property (nullable, nonatomic) RCTBridge * bridge;
@property (nullable, nonatomic) NSDictionary * options;
@property (nullable, nonatomic) RNFetchBlobFS * fileStream;
@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
//@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
//@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
@property (nullable, nonatomic) NSError * error;


Expand Down
48 changes: 26 additions & 22 deletions src/ios/RNFetchBlobNetwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ @implementation RNFetchBlobNetwork
@synthesize callback;
@synthesize bridge;
@synthesize options;
@synthesize fileTaskCompletionHandler;
@synthesize dataTaskCompletionHandler;
//@synthesize fileTaskCompletionHandler;
//@synthesize dataTaskCompletionHandler;
@synthesize error;


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

self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// self.fileTaskCompletionHandler = ;
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error != nil) {
callback(@[[error localizedDescription]]);
return;
Expand All @@ -102,14 +103,16 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
return;
}
callback(@[[NSNull null], path]);
};
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
// prevent memory leaks
self.respData = nil;
}];
[task resume];
}
// file will be stored at tmp path
else if ( [self.options valueForKey:CONFIG_USE_TEMP]!= nil ) {

self.fileTaskCompletionHandler = ^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// self.fileTaskCompletionHandler;
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error != nil) {
callback(@[[error localizedDescription]]);
return;
Expand All @@ -124,22 +127,23 @@ - (void) sendRequest:(NSDictionary * _Nullable )options bridge:(RCTBridge * _Nu
return;
}
callback(@[[NSNull null], tmpPath]);
};
NSURLSessionDownloadTask * task = [session downloadTaskWithRequest:req completionHandler:fileTaskCompletionHandler];
// prevent memory leaks
self.respData = nil;
}];
[task resume];
}
// base64 response
else {
self.dataTaskCompletionHandler = ^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
// self.dataTaskCompletionHandler = ;
NSURLSessionDataTask * task = [session dataTaskWithRequest:req completionHandler:^(NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if(error != nil) {
callback(@[[error localizedDescription]]);
return;
}
else {
callback(@[[NSNull null], [resp base64EncodedStringWithOptions:0]]);
}
};
NSURLSessionDataTask * task = [session dataTaskWithRequest:req completionHandler:dataTaskCompletionHandler];
}];
[task resume];
}
}
Expand Down Expand Up @@ -205,17 +209,17 @@ - (void) application:(UIApplication *)application handleEventsForBackgroundURLSe

}

- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
{
if(self.dataTaskCompletionHandler != nil)
{
dataTaskCompletionHandler(self.respData, nil, error);
}
else if(self.fileTaskCompletionHandler != nil)
{
fileTaskCompletionHandler(nil, nil, self.error);
}
}
//- (void) URLSessionDidFinishEventsForBackgroundURLSession:(NSURLSession *)session
//{
// if(self.dataTaskCompletionHandler != nil)
// {
// dataTaskCompletionHandler(self.respData, nil, error);
// }
// else if(self.fileTaskCompletionHandler != nil)
// {
// fileTaskCompletionHandler(nil, nil, self.error);
// }
//}

- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-fetch-blob",
"version": "0.5.4",
"version": "0.5.5",
"description": "A module provides upload, download, and files access API. Supports file stream read/write for process large files.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 24df33c

Please sign in to comment.