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

Commit ab110ce

Browse files
committed
Fix zero division error
1 parent d8d392c commit ab110ce

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public FormField(ReadableMap rawData) {
372372
*/
373373
private void emitUploadProgress(int written) {
374374
RNFetchBlobProgressConfig config = RNFetchBlobReq.getReportUploadProgress(mTaskId);
375-
if(config.enable && config.shouldReport((float)written/contentLength)) {
375+
if(config != null && contentLength != 0 && config.shouldReport((float)written/contentLength)) {
376376
WritableMap args = Arguments.createMap();
377377
args.putString("taskId", mTaskId);
378378
args.putString("written", String.valueOf(written));

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ enum ResponseFormat {
9292
ResponseFormat responseFormat = ResponseFormat.Auto;
9393
WritableMap respInfo;
9494
boolean timeout = false;
95-
9695
ArrayList<String> redirects = new ArrayList<>();
9796

9897
public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {

src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobDefaultResp.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public long read(Buffer sink, long byteCount) throws IOException {
6363
long read = mOriginalSource.read(sink, byteCount);
6464
bytesRead += read > 0 ? read : 0;
6565
RNFetchBlobProgressConfig reportConfig = RNFetchBlobReq.getReportProgress(mTaskId);
66-
if(reportConfig != null && reportConfig.shouldReport(bytesRead/contentLength())) {
66+
long cLen = contentLength();
67+
if(reportConfig != null && cLen != 0 && reportConfig.shouldReport(bytesRead/contentLength())) {
6768
WritableMap args = Arguments.createMap();
6869
args.putString("taskId", mTaskId);
6970
args.putString("written", String.valueOf(bytesRead));

src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public long read(Buffer sink, long byteCount) throws IOException {
8080
ofStream.write(bytes, 0, (int) read);
8181
}
8282
RNFetchBlobProgressConfig reportConfig = RNFetchBlobReq.getReportProgress(mTaskId);
83-
if (reportConfig != null && reportConfig.shouldReport(bytesDownloaded / contentLength())) {
83+
if (reportConfig != null && contentLength() != 0 &&reportConfig.shouldReport(bytesDownloaded / contentLength())) {
8484
WritableMap args = Arguments.createMap();
8585
args.putString("taskId", mTaskId);
8686
args.putString("written", String.valueOf(bytesDownloaded));

src/ios/RNFetchBlobNetwork.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ - (void) URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dat
325325
[writeStream write:[data bytes] maxLength:[data length]];
326326
}
327327
RNFetchBlobProgress * pconfig = [progressTable valueForKey:taskId];
328+
if(expectedBytes == 0)
329+
return;
328330
NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
329331
if(pconfig != nil && [pconfig shouldReport:now])
330332
{
@@ -430,6 +432,8 @@ - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCom
430432
- (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite
431433
{
432434
RNFetchBlobProgress * pconfig = [uploadProgressTable valueForKey:taskId];
435+
if(totalBytesExpectedToWrite == 0)
436+
return;
433437
NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
434438
if(pconfig != nil && [pconfig shouldReport:now]) {
435439
[self.bridge.eventDispatcher

0 commit comments

Comments
 (0)