Skip to content
This repository was archived by the owner on Feb 27, 2022. It is now read-only.

Commit 1d38be3

Browse files
author
Elad Gil
committed
changer all the "download" to "downloader" since npm doesn't like the name
1 parent 4ffc7f3 commit 1d38be3

File tree

8 files changed

+68
-68
lines changed

8 files changed

+68
-68
lines changed

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# react-native-background-download
2+
# react-native-background-downloader
33

44
A library for React-Native to help you download large files on iOS and Android both in the foreground and most importantly in the background.
55

@@ -12,7 +12,7 @@ On Android we are simulating this process with a separate service dedicated to j
1212

1313
The real challenge using this method is making sure the app's UI if always up-to-date with the downloads that are happening in another process because your app might startup from scratch while the downloads are still running.
1414

15-
`react-native-background-download` gives you an easy API to both downloading large files and re-attaching to those downloads once your app launches again.
15+
`react-native-background-downloader` gives you an easy API to both downloading large files and re-attaching to those downloads once your app launches again.
1616

1717
## ToC
1818

@@ -22,48 +22,48 @@ The real challenge using this method is making sure the app's UI if always up-to
2222

2323
## Getting started
2424

25-
`$ npm install react-native-background-download --save`
25+
`$ npm install react-native-background-downloader --save`
2626

2727
### Mostly automatic installation
2828

29-
`$ react-native link react-native-background-download`
29+
`$ react-native link react-native-background-downloader`
3030

3131
### Manual installation
3232

3333

3434
#### iOS
3535

3636
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
37-
2. Go to `node_modules``react-native-background-download` and add `RNBackgroundDownload.xcodeproj`
38-
3. In XCode, in the project navigator, select your project. Add `libRNBackgroundDownload.a` to your project's `Build Phases``Link Binary With Libraries`
37+
2. Go to `node_modules``react-native-background-downloader` and add `RNBackgroundDownloader.xcodeproj`
38+
3. In XCode, in the project navigator, select your project. Add `libRNBackgroundDownloader.a` to your project's `Build Phases``Link Binary With Libraries`
3939
4. Run your project (`Cmd+R`)
4040

4141
#### Android
4242

4343
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
44-
- Add `import com.eko.RNBackgroundDownloadPackage;` to the imports at the top of the file
45-
- Add `new RNBackgroundDownloadPackage()` to the list returned by the `getPackages()` method
44+
- Add `import com.eko.RNBackgroundDownloaderPackage;` to the imports at the top of the file
45+
- Add `new RNBackgroundDownloaderPackage()` to the list returned by the `getPackages()` method
4646
2. Append the following lines to `android/settings.gradle`:
4747
```
48-
include ':react-native-background-download'
49-
project(':react-native-background-download').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-download/android')
48+
include ':react-native-background-downloader'
49+
project(':react-native-background-downloader').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-background-downloader/android')
5050
```
5151
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
5252
```
53-
compile project(':react-native-background-download')
53+
compile project(':react-native-background-downloader')
5454
```
5555

5656
### iOS - Extra Mandatory Step
5757
In your `AppDelegate.m` add the following code:
5858
```objc
5959
...
60-
#import <RNBackgroundDownload.h>
60+
#import <RNBackgroundDownloader.h>
6161

6262
...
6363

6464
- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(NSString *)identifier completionHandler:(void (^)())completionHandler
6565
{
66-
[RNBackgroundDownload setCompletionHandlerWithIdentifier:identifier completionHandler:completionHandler];
66+
[RNBackgroundDownloader setCompletionHandlerWithIdentifier:identifier completionHandler:completionHandler];
6767
}
6868

6969
...
@@ -75,12 +75,12 @@ Failing to add this code will result in canceled background downloads.
7575
### Downloading a file
7676

7777
```javascript
78-
import RNBackgroundDownload from 'react-native-background-download';
78+
import RNBackgroundDownloader from 'react-native-background-downloader';
7979

80-
let task = RNBackgroundDownload.download({
80+
let task = RNBackgroundDownloader.download({
8181
id: 'file123',
8282
url: 'https://link-to-very.large/file.zip'
83-
destination: `${RNBackgroundDownload.directories.documents}/file.zip`
83+
destination: `${RNBackgroundDownloader.directories.documents}/file.zip`
8484
}).begin((expectedBytes) => {
8585
console.log(`Going to download ${expectedBytes} bytes!`);
8686
}).progress((percent) => {
@@ -110,9 +110,9 @@ What happens to your downloads after the OS stopped your app? Well, they are sti
110110
Add this code to app's init stage, and you'll never lose a download again!
111111

112112
```javascript
113-
import RNBackgroundDownload from 'react-native-background-download';
113+
import RNBackgroundDownloader from 'react-native-background-downloader';
114114

115-
let lostTasks = await RNBackgroundDownload.checkForExistingDownloads();
115+
let lostTasks = await RNBackgroundDownloader.checkForExistingDownloads();
116116
for (let task of lostTask) {
117117
console.log(`Task ${task.id} was found!`);
118118
task.progress((percent) => {
@@ -129,7 +129,7 @@ for (let task of lostTask) {
129129

130130
## API
131131

132-
### RNBackgroundDownload
132+
### RNBackgroundDownloader
133133

134134
### `download(options)`
135135

@@ -161,12 +161,12 @@ Checks for downloads that ran in background while you app was terminated. Recomm
161161

162162
### DownloadTask
163163

164-
A class representing a download task created by `RNBackgroundDownload.download`
164+
A class representing a download task created by `RNBackgroundDownloader.download`
165165

166166
### `Members`
167167
| Name | Type | Info |
168168
| -------------- | ------ | ---------------------------------------------------------------------------------------------------- |
169-
| `id` | String | The id you gave the task when calling `RNBackgroundDownload.download` |
169+
| `id` | String | The id you gave the task when calling `RNBackgroundDownloader.download` |
170170
| `percent` | Number | The current percent of completion of the task between 0 and 1 |
171171
| `bytesWritten` | Number | The number of bytes currently written by the task |
172172
| `totalBytes` | Number | The number bytes expected to be written by this task or more plainly, the file size being downloaded |

android/src/main/java/com/eko/RNBackgroundDownloadModule.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
import javax.annotation.Nullable;
3939

40-
public class RNBackgroundDownloadModule extends ReactContextBaseJavaModule implements FetchListener {
40+
public class RNBackgroundDownloaderModule extends ReactContextBaseJavaModule implements FetchListener {
4141

4242
private static final int TASK_RUNNING = 0;
4343
private static final int TASK_SUSPENDED = 1;
@@ -64,11 +64,11 @@ public class RNBackgroundDownloadModule extends ReactContextBaseJavaModule imple
6464
private Date lastProgressReport = new Date();
6565
private HashMap<String, WritableMap> progressReports = new HashMap<>();
6666

67-
public RNBackgroundDownloadModule(ReactApplicationContext reactContext) {
67+
public RNBackgroundDownloaderModule(ReactApplicationContext reactContext) {
6868
super(reactContext);
6969

7070
loadConfigMap();
71-
fetch = new Fetch.Builder(this.getReactApplicationContext(), "RNBackgroundDownload")
71+
fetch = new Fetch.Builder(this.getReactApplicationContext(), "RNBackgroundDownloader")
7272
.setDownloadConcurrentLimit(4)
7373
.build();
7474
fetch.addListener(this);
@@ -81,7 +81,7 @@ public void onCatalystInstanceDestroy() {
8181

8282
@Override
8383
public String getName() {
84-
return "RNBackgroundDownload";
84+
return "RNBackgroundDownloader";
8585
}
8686

8787
@Override

android/src/main/java/com/eko/RNBackgroundDownloadPackage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
import com.facebook.react.bridge.ReactApplicationContext;
1111
import com.facebook.react.uimanager.ViewManager;
1212
import com.facebook.react.bridge.JavaScriptModule;
13-
public class RNBackgroundDownloadPackage implements ReactPackage {
13+
public class RNBackgroundDownloaderPackage implements ReactPackage {
1414
@Override
1515
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16-
return Arrays.<NativeModule>asList(new RNBackgroundDownloadModule(reactContext));
16+
return Arrays.<NativeModule>asList(new RNBackgroundDownloaderModule(reactContext));
1717
}
1818

1919
@Override

index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { NativeModules, NativeEventEmitter } from 'react-native';
2-
const { RNBackgroundDownload } = NativeModules;
3-
const RNBackgroundDownloadEmitter = new NativeEventEmitter(RNBackgroundDownload);
2+
const { RNBackgroundDownloader } = NativeModules;
3+
const RNBackgroundDownloaderEmitter = new NativeEventEmitter(RNBackgroundDownloader);
44
import DownloadTask from './lib/downloadTask';
55

66
const tasksMap = new Map();
77

8-
RNBackgroundDownloadEmitter.addListener('downloadProgress', events => {
8+
RNBackgroundDownloaderEmitter.addListener('downloadProgress', events => {
99
for (let event of events) {
1010
let task = tasksMap.get(event.id);
1111
if (task) {
@@ -14,42 +14,42 @@ RNBackgroundDownloadEmitter.addListener('downloadProgress', events => {
1414
}
1515
});
1616

17-
RNBackgroundDownloadEmitter.addListener('downloadComplete', event => {
17+
RNBackgroundDownloaderEmitter.addListener('downloadComplete', event => {
1818
let task = tasksMap.get(event.id);
1919
if (task) {
2020
task._onDone(event.location);
2121
}
2222
tasksMap.delete(event.id);
2323
});
2424

25-
RNBackgroundDownloadEmitter.addListener('downloadFailed', event => {
25+
RNBackgroundDownloaderEmitter.addListener('downloadFailed', event => {
2626
let task = tasksMap.get(event.id);
2727
if (task) {
2828
task._onError(event.error);
2929
}
3030
tasksMap.delete(event.id);
3131
});
3232

33-
RNBackgroundDownloadEmitter.addListener('downloadBegin', event => {
33+
RNBackgroundDownloaderEmitter.addListener('downloadBegin', event => {
3434
let task = tasksMap.get(event.id);
3535
if (task) {
3636
task._onBegin(event.expectedBytes);
3737
}
3838
});
3939

4040
export function checkForExistingDownloads() {
41-
return RNBackgroundDownload.checkForExistingDownloads()
41+
return RNBackgroundDownloader.checkForExistingDownloads()
4242
.then(foundTasks => {
4343
return foundTasks.map(taskInfo => {
4444
let task = new DownloadTask(taskInfo);
45-
if (taskInfo.state === RNBackgroundDownload.TaskRunning) {
45+
if (taskInfo.state === RNBackgroundDownloader.TaskRunning) {
4646
task.state = 'DOWNLOADING';
47-
} else if (taskInfo.state === RNBackgroundDownload.TaskSuspended) {
47+
} else if (taskInfo.state === RNBackgroundDownloader.TaskSuspended) {
4848
task.state = 'PAUSED';
49-
} else if (taskInfo.state === RNBackgroundDownload.TaskCanceling) {
49+
} else if (taskInfo.state === RNBackgroundDownloader.TaskCanceling) {
5050
task.stop();
5151
return null;
52-
} else if (taskInfo.state === RNBackgroundDownload.TaskCompleted) {
52+
} else if (taskInfo.state === RNBackgroundDownloader.TaskCompleted) {
5353
if (taskInfo.bytesWritten === taskInfo.totalBytes) {
5454
task.state = 'DONE';
5555
} else {
@@ -65,27 +65,27 @@ export function checkForExistingDownloads() {
6565

6666
export function download(options) {
6767
if (!options.id || !options.url || !options.destination) {
68-
throw new Error('[RNBackgroundDownload] id, url and destination are required');
68+
throw new Error('[RNBackgroundDownloader] id, url and destination are required');
6969
}
70-
RNBackgroundDownload.download(options);
70+
RNBackgroundDownloader.download(options);
7171
let task = new DownloadTask(options.id);
7272
tasksMap.set(options.id, task);
7373
return task;
7474
}
7575

7676
export const directories = {
77-
documents: RNBackgroundDownload.documents
77+
documents: RNBackgroundDownloader.documents
7878
};
7979

8080
export const Network = {
81-
WIFI_ONLY: RNBackgroundDownload.OnlyWifi,
82-
ALL: RNBackgroundDownload.AllNetworks
81+
WIFI_ONLY: RNBackgroundDownloader.OnlyWifi,
82+
ALL: RNBackgroundDownloader.AllNetworks
8383
};
8484

8585
export const Priority = {
86-
HIGH: RNBackgroundDownload.PriorityHigh,
87-
MEDIUM: RNBackgroundDownload.PriorityNormal,
88-
LOW: RNBackgroundDownload.PriorityLow
86+
HIGH: RNBackgroundDownloader.PriorityHigh,
87+
MEDIUM: RNBackgroundDownloader.PriorityNormal,
88+
LOW: RNBackgroundDownloader.PriorityLow
8989
};
9090

9191
export default {

ios/RNBackgroundDownload.h renamed to ios/RNBackgroundDownloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
typedef void (^CompletionHandler)();
1919

20-
@interface RNBackgroundDownload : RCTEventEmitter <RCTBridgeModule, NSURLSessionDelegate, NSURLSessionDownloadDelegate>
20+
@interface RNBackgroundDownloader : RCTEventEmitter <RCTBridgeModule, NSURLSessionDelegate, NSURLSessionDownloadDelegate>
2121

2222
+ (void)setCompletionHandlerWithIdentifier: (NSString *)identifier completionHandler: (CompletionHandler)completionHandler;
2323

ios/RNBackgroundDownload.m renamed to ios/RNBackgroundDownloader.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static CompletionHandler storedCompletionHandler;
1515

16-
@implementation RNBackgroundDownload {
16+
@implementation RNBackgroundDownloader {
1717
NSURLSession *urlSession;
1818
NSURLSessionConfiguration *sessionConfig;
1919
NSMutableDictionary<NSString *, RNBGDTaskConfig *> *urlToConfigMap;

0 commit comments

Comments
 (0)