Parcourir la source

code refactor

Ben Hsieh il y a 7 ans
Parent
révision
8e9863624c

+ 6
- 14
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Voir le fichier

@@ -77,7 +77,6 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
77 77
     static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
78 78
     static ConnectionPool pool = new ConnectionPool();
79 79
 
80
-    MediaType contentType = RNFetchBlobConst.MIME_OCTET;
81 80
     ReactApplicationContext ctx;
82 81
     RNFetchBlobConfig options;
83 82
     String taskId;
@@ -94,8 +93,6 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
94 93
     ResponseType responseType;
95 94
     WritableMap respInfo;
96 95
     boolean timeout = false;
97
-    public boolean reportProgress = false;
98
-    public boolean reportUploadProgress = false;
99 96
 
100 97
     public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
101 98
         this.method = method.toUpperCase();
@@ -398,8 +395,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
398 395
             case KeepInMemory:
399 396
                 try {
400 397
                     // For XMLHttpRequest, automatic response data storing strategy, when response
401
-                    // header is not `application/json` or `text/plain`, write response data to
402
-                    // file system.
398
+                    // data is considered as binary data, write it to file system
403 399
                     if(isBlobResp && options.auto == true) {
404 400
                         String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
405 401
                         InputStream ins = resp.body().byteStream();
@@ -418,7 +414,6 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
418 414
                         // #73 Check if the response data contains valid UTF8 string, since BASE64
419 415
                         // encoding will somehow break the UTF8 string format, to encode UTF8
420 416
                         // string correctly, we should do URL encoding before BASE64.
421
-                        String utf8Str;
422 417
                         byte[] b = resp.body().bytes();
423 418
                         CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
424 419
                         try {
@@ -426,10 +421,9 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
426 421
                             // if the data can be encoded to UTF8 append URL encode
427 422
                             b = URLEncoder.encode(new String(b), "UTF-8").replace("+", "%20").getBytes();
428 423
                         }
429
-                        // This usually mean the data is binary data
430
-                        catch(CharacterCodingException e) {
431
-
432
-                        }
424
+                        // This usually mean the data is contains invalid unicode characters, it's
425
+                        // binary data
426
+                        catch(CharacterCodingException ignored) {}
433 427
                         finally {
434 428
                             callback.invoke(null, null, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
435 429
                         }
@@ -439,14 +433,12 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
439 433
                 }
440 434
                 break;
441 435
             case FileStorage:
442
-                try{
436
+                try {
443 437
                     // In order to write response data to `destPath` we have to invoke this method.
444 438
                     // It uses customized response body which is able to report download progress
445 439
                     // and write response data to destination path.
446 440
                     resp.body().bytes();
447
-                } catch (Exception ignored) {
448
-
449
-                }
441
+                } catch (Exception ignored) {}
450 442
                 callback.invoke(null, null, this.destPath);
451 443
                 break;
452 444
             default:

+ 1
- 1
src/polyfill/Blob.js Voir le fichier

@@ -281,7 +281,7 @@ function createMixedBlobData(ref, dataArray) {
281 281
       return fs.appendFile.call(this, ...p)
282 282
     })
283 283
     return Promise.all(promises).then((sizes) => {
284
-      console.log('blob write size', sizes)
284
+      log.verbose('blob write size', sizes)
285 285
       for(let i in sizes) {
286 286
         size += sizes[i]
287 287
       }