Bläddra i källkod

Fix zero division error

Ben Hsieh 8 år sedan
förälder
incheckning
ab110cebdc

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobBody.java Visa fil

@@ -372,7 +372,7 @@ public class RNFetchBlobBody extends RequestBody{
372 372
      */
373 373
     private void emitUploadProgress(int written) {
374 374
         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)) {
376 376
             WritableMap args = Arguments.createMap();
377 377
             args.putString("taskId", mTaskId);
378 378
             args.putString("written", String.valueOf(written));

+ 0
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Visa fil

@@ -92,7 +92,6 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
92 92
     ResponseFormat responseFormat = ResponseFormat.Auto;
93 93
     WritableMap respInfo;
94 94
     boolean timeout = false;
95
-
96 95
     ArrayList<String> redirects = new ArrayList<>();
97 96
 
98 97
     public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {

+ 2
- 1
src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobDefaultResp.java Visa fil

@@ -63,7 +63,8 @@ public class RNFetchBlobDefaultResp extends ResponseBody {
63 63
             long read =  mOriginalSource.read(sink, byteCount);
64 64
             bytesRead += read > 0 ? read : 0;
65 65
             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())) {
67 68
                 WritableMap args = Arguments.createMap();
68 69
                 args.putString("taskId", mTaskId);
69 70
                 args.putString("written", String.valueOf(bytesRead));

+ 1
- 1
src/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java Visa fil

@@ -80,7 +80,7 @@ public class RNFetchBlobFileResp extends ResponseBody {
80 80
                     ofStream.write(bytes, 0, (int) read);
81 81
                 }
82 82
                 RNFetchBlobProgressConfig reportConfig = RNFetchBlobReq.getReportProgress(mTaskId);
83
-                if (reportConfig != null && reportConfig.shouldReport(bytesDownloaded / contentLength())) {
83
+                if (reportConfig != null && contentLength() != 0 &&reportConfig.shouldReport(bytesDownloaded / contentLength())) {
84 84
                     WritableMap args = Arguments.createMap();
85 85
                     args.putString("taskId", mTaskId);
86 86
                     args.putString("written", String.valueOf(bytesDownloaded));

+ 4
- 0
src/ios/RNFetchBlobNetwork.m Visa fil

@@ -325,6 +325,8 @@ NSOperationQueue *taskQueue;
325 325
         [writeStream write:[data bytes] maxLength:[data length]];
326 326
     }
327 327
     RNFetchBlobProgress * pconfig = [progressTable valueForKey:taskId];
328
+    if(expectedBytes == 0)
329
+        return;
328 330
     NSNumber * now =[NSNumber numberWithFloat:((float)receivedBytes/(float)expectedBytes)];
329 331
     if(pconfig != nil && [pconfig shouldReport:now])
330 332
     {
@@ -430,6 +432,8 @@ NSOperationQueue *taskQueue;
430 432
 - (void) URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didSendBodyData:(int64_t)bytesSent totalBytesSent:(int64_t)totalBytesWritten totalBytesExpectedToSend:(int64_t)totalBytesExpectedToWrite
431 433
 {
432 434
     RNFetchBlobProgress * pconfig = [uploadProgressTable valueForKey:taskId];
435
+    if(totalBytesExpectedToWrite == 0)
436
+        return;
433 437
     NSNumber * now = [NSNumber numberWithFloat:((float)totalBytesWritten/(float)totalBytesExpectedToWrite)];
434 438
     if(pconfig != nil && [pconfig shouldReport:now]) {
435 439
         [self.bridge.eventDispatcher