|
599 | 599 | if (!averageSpeed) { |
600 | 600 | return Number.POSITIVE_INFINITY; |
601 | 601 | } |
602 | | - return sizeDelta / averageSpeed; |
| 602 | + return Math.floor(sizeDelta / averageSpeed); |
603 | 603 | } |
604 | 604 | }; |
605 | 605 |
|
|
909 | 909 | sizeUploaded: function () { |
910 | 910 | var size = 0; |
911 | 911 | each(this.chunks, function (chunk) { |
912 | | - // can't sum only chunk.loaded values, because it is bigger than chunk size |
913 | | - if (chunk.status() === 'success') { |
914 | | - size += chunk.endByte - chunk.startByte; |
915 | | - } else { |
916 | | - size += chunk.loaded; |
917 | | - } |
| 912 | + size += chunk.sizeUploaded(); |
918 | 913 | }); |
919 | 914 | return size; |
920 | 915 | }, |
|
929 | 924 | if (!this.averageSpeed) { |
930 | 925 | return Number.POSITIVE_INFINITY; |
931 | 926 | } |
932 | | - return Math.floor(Math.max(this.size - this.sizeUploaded(), 0) / this.averageSpeed); |
| 927 | + return Math.floor((this.size - this.sizeUploaded()) / this.averageSpeed); |
933 | 928 | }, |
934 | 929 |
|
935 | 930 | /** |
|
1290 | 1285 | } |
1291 | 1286 | }, |
1292 | 1287 |
|
| 1288 | + /** |
| 1289 | + * Count total size uploaded |
| 1290 | + * @function |
| 1291 | + * @returns {number} |
| 1292 | + */ |
| 1293 | + sizeUploaded: function () { |
| 1294 | + var size = this.endByte - this.startByte; |
| 1295 | + // can't return only chunk.loaded value, because it is bigger than chunk size |
| 1296 | + if (this.status() !== 'success') { |
| 1297 | + size = this.progress() * size; |
| 1298 | + } |
| 1299 | + return size; |
| 1300 | + }, |
| 1301 | + |
1293 | 1302 | /** |
1294 | 1303 | * Prepare Xhr request. Set query, headers and data |
1295 | 1304 | * @param {string} method GET or POST |
|
1399 | 1408 | * @type {FlowChunk} |
1400 | 1409 | */ |
1401 | 1410 | Flow.FlowChunk = FlowChunk; |
1402 | | - |
| 1411 | + |
1403 | 1412 | if (typeof module !== 'undefined') { |
1404 | 1413 | module.exports = Flow; |
1405 | 1414 | } else if (typeof define === "function" && define.amd) { |
|
0 commit comments