react-native-blob-util 0.24.10 → 0.24.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -217,7 +217,7 @@ public class ReactNativeBlobUtilReq extends BroadcastReceiver implements Runnabl
217
217
  cursor.close();
218
218
 
219
219
  ReactNativeBlobUtilProgressConfig reportConfig = getReportProgress(taskId);
220
- float progress = (total > 0) ? written / total : 0;
220
+ float progress = (total > 0) ? (float) written / total : 0;
221
221
 
222
222
  if (reportConfig != null && reportConfig.shouldReport(progress /* progress */)) {
223
223
  WritableMap args = Arguments.createMap();
@@ -67,7 +67,7 @@ public class ReactNativeBlobUtilDefaultResp extends ResponseBody {
67
67
  bytesRead += read > 0 ? read : 0;
68
68
  ReactNativeBlobUtilProgressConfig reportConfig = ReactNativeBlobUtilReq.getReportProgress(mTaskId);
69
69
  long cLen = contentLength();
70
- if (reportConfig != null && cLen != 0 && reportConfig.shouldReport(bytesRead / contentLength())) {
70
+ if (reportConfig != null && cLen != 0 && reportConfig.shouldReport(cLen > 0 ? (float) bytesRead / cLen : 0)) {
71
71
  WritableMap args = Arguments.createMap();
72
72
  args.putString("taskId", mTaskId);
73
73
  args.putString("written", String.valueOf(bytesRead));
@@ -123,6 +123,11 @@ public class ReactNativeBlobUtilFileResp extends ResponseBody {
123
123
  bytesDownloaded += read > 0 ? read : 0;
124
124
  if (read > 0) {
125
125
  ofStream.write(bytes, 0, (int) read);
126
+ // Forward bytes into the Okio sink too. Without this the buffer
127
+ // stays empty and buffered consumers (byteStream()/source().read())
128
+ // hit a false EOF after the first 8 KB segment, so any file larger
129
+ // than one segment fails with "Download interrupted." (0.24.10 regression).
130
+ sink.write(bytes, 0, (int) read);
126
131
  } else if (contentLength() == -1 && read == -1) {
127
132
  // End marker has been received for chunked download
128
133
  isEndMarkerReceived = true;
@@ -133,7 +138,7 @@ public class ReactNativeBlobUtilFileResp extends ResponseBody {
133
138
 
134
139
  // For non-chunked download, progress is received / total
135
140
  // For chunked download, progress can be either 0 (started) or 1 (ended)
136
- float progress = (contentLength() != -1) ? bytesDownloaded / contentLength() : ((isEndMarkerReceived) ? 1 : 0);
141
+ float progress = (contentLength() != -1) ? (float) bytesDownloaded / contentLength() : ((isEndMarkerReceived) ? 1 : 0);
137
142
 
138
143
  if (reportConfig != null && reportConfig.shouldReport(progress /* progress */)) {
139
144
  if (contentLength() != -1) {