forked from itinance/react-native-fs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored downloadFile, added stopDownload
- Loading branch information
Showing
10 changed files
with
303 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
typedef void (^DownloaderCallback)(NSNumber*, NSNumber*); | ||
typedef void (^ErrorCallback)(NSError*); | ||
typedef void (^DownloaderCallback)(NSNumber*, NSNumber*, NSNumber*); | ||
typedef void (^BeginCallback)(NSNumber*, NSNumber*, NSDictionary*); | ||
typedef void (^ProgressCallback)(NSNumber*, NSNumber*); | ||
|
||
@interface DownloadParams : NSObject | ||
|
||
@property (copy) NSString* fromUrl; | ||
@property (copy) NSString* toFile; | ||
@property (copy) DownloaderCallback callback; // Download has finished (data written) | ||
@property (copy) ErrorCallback errorCallback; // Something went wrong | ||
@property (copy) BeginCallback beginCallback; // Download has started (headers received) | ||
@property (copy) ProgressCallback progressCallback; // Download is progressing | ||
|
||
@end | ||
|
||
@interface Downloader : NSObject <NSURLConnectionDelegate> | ||
|
||
- (void)downloadFile:(NSString*)urlStr toFile:(NSString*)downloadPath callback:(DownloaderCallback)callback errorCallback:(ErrorCallback)errorCallback progressCallback:(DownloaderCallback)progressCallback; | ||
- (void)downloadFile:(DownloadParams*)params; | ||
- (void)stopDownload; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.rnfs; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.util.*; | ||
|
||
public class DownloadParams { | ||
public interface OnTaskCompleted { | ||
void onTaskCompleted(DownloadResult res); | ||
} | ||
|
||
public interface OnDownloadBegin { | ||
void onDownloadBegin(int statusCode, int contentLength, Map<String, String> headers); | ||
} | ||
|
||
public interface OnDownloadProgress { | ||
void onDownloadProgress(int contentLength, int bytesWritten); | ||
} | ||
|
||
public URL src; | ||
public File dest; | ||
public OnTaskCompleted onTaskCompleted; | ||
public OnDownloadBegin onDownloadBegin; | ||
public OnDownloadProgress onDownloadProgress; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.rnfs; | ||
|
||
public class DownloadResult { | ||
public int statusCode; | ||
public int bytesWritten; | ||
public Exception exception; | ||
} |
Oops, something went wrong.