itinance / itinance/react-native-fs

Download block UI thread with small file

Open
#193 8 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I'm using RNFS for downloading file inside an app. Sometimes I can use the app during a download but sometimes not.

I've tested with a small file (~10Mo) and the bug occurs, but with a large file (~1Go) it doesn't.

When I check the log with XCode, I can see, with the small file, that the percentage displayed within the app is not the same that it displayed within Xcode. But with the big file I don't have this problem.

I just tested on Android too, and I get the same weird behavior.

Here is the code I'm using. I tried without progressDivider but same result.

``` js
download = (idCourse) => {
begin = (res) => {
if (res.statusCode == '404') {
this.props.cancelDownload(this.props.course.id_course)
return false
} else {
this.jobId = res.jobId
this.props.setPercentage(this.props.course.id_course, 0, this.jobId)
}
}

progress = (data) => {
const percentage = ((100 * data.bytesWritten) / data.contentLength) | 0;
this.props.setPercentage(this.props.course.id_course, percentage, this.jobId)
}
const localPath = this.props.course.id_course + '.zip';
const remoteURL = getCourseZipUrl(this.props.course.id_course)
const downloadDirectory = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath + '/downloads/' : RNFS.ExternalDirectoryPath + '/downloads/';

const realLocalPath = downloadDirectory + '/' + localPath;
const progressDivider = 1;
const ret = RNFS.downloadFile({fromUrl: remoteURL, toFile: realLocalPath, begin, progress, false, progressDivider})
ret.promise.then(res => {
if (res.statusCode == '404') {
this.props.cancelDownload(this.props.course.id_course)
} else{
this.props.setFinished(this.props.course.id_course)
}
}).catch(err => {
console.log('errorDL', err)
})
}

stopDownload = (idJob) => {
if (idJob !== -1) {
RNFS.stopDownload(idJob);
this.props.cancelDownload(this.props.course.id_course)
}
}
```
### Without the bug

![download_without_bug](https://cloud.githubusercontent.com/assets/1107936/19654591/45823152-9a19-11e6-8e5c-dfc6769256e9.gif)
### With the bug

![bug_dl](https://cloud.githubusercontent.com/assets/1107936/19654969/a98efaa8-9a1a-11e6-8f6d-dda0129f50b9.gif)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.