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

Commit 8e98636

Browse files
committed
code refactor
1 parent 64ac7f2 commit 8e98636

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ enum ResponseType {
7777
static HashMap<String, Boolean> uploadProgressReport = new HashMap<>();
7878
static ConnectionPool pool = new ConnectionPool();
7979

80-
MediaType contentType = RNFetchBlobConst.MIME_OCTET;
8180
ReactApplicationContext ctx;
8281
RNFetchBlobConfig options;
8382
String taskId;
@@ -94,8 +93,6 @@ enum ResponseType {
9493
ResponseType responseType;
9594
WritableMap respInfo;
9695
boolean timeout = false;
97-
public boolean reportProgress = false;
98-
public boolean reportUploadProgress = false;
9996

10097
public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
10198
this.method = method.toUpperCase();
@@ -398,8 +395,7 @@ private void done(Response resp) {
398395
case KeepInMemory:
399396
try {
400397
// 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
403399
if(isBlobResp && options.auto == true) {
404400
String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
405401
InputStream ins = resp.body().byteStream();
@@ -418,18 +414,16 @@ private void done(Response resp) {
418414
// #73 Check if the response data contains valid UTF8 string, since BASE64
419415
// encoding will somehow break the UTF8 string format, to encode UTF8
420416
// string correctly, we should do URL encoding before BASE64.
421-
String utf8Str;
422417
byte[] b = resp.body().bytes();
423418
CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
424419
try {
425420
encoder.encode(ByteBuffer.wrap(b).asCharBuffer());
426421
// if the data can be encoded to UTF8 append URL encode
427422
b = URLEncoder.encode(new String(b), "UTF-8").replace("+", "%20").getBytes();
428423
}
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) {}
433427
finally {
434428
callback.invoke(null, null, android.util.Base64.encodeToString(b, Base64.NO_WRAP));
435429
}
@@ -439,14 +433,12 @@ private void done(Response resp) {
439433
}
440434
break;
441435
case FileStorage:
442-
try{
436+
try {
443437
// In order to write response data to `destPath` we have to invoke this method.
444438
// It uses customized response body which is able to report download progress
445439
// and write response data to destination path.
446440
resp.body().bytes();
447-
} catch (Exception ignored) {
448-
449-
}
441+
} catch (Exception ignored) {}
450442
callback.invoke(null, null, this.destPath);
451443
break;
452444
default:

src/polyfill/Blob.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ function createMixedBlobData(ref, dataArray) {
281281
return fs.appendFile.call(this, ...p)
282282
})
283283
return Promise.all(promises).then((sizes) => {
284-
console.log('blob write size', sizes)
284+
log.verbose('blob write size', sizes)
285285
for(let i in sizes) {
286286
size += sizes[i]
287287
}

0 commit comments

Comments
 (0)