|
1146 | 1146 | */ |
1147 | 1147 | this.startByte = this.offset * this.chunkSize; |
1148 | 1148 |
|
| 1149 | + /** |
| 1150 | + * Compute the endbyte in a file |
| 1151 | + * |
| 1152 | + */ |
| 1153 | + this.computeEndByte = function() { |
| 1154 | + var endByte = Math.min(this.fileObj.size, (this.offset + 1) * this.chunkSize); |
| 1155 | + if (this.fileObj.size - endByte < this.chunkSize && !this.flowObj.opts.forceChunkSize) { |
| 1156 | + // The last chunk will be bigger than the chunk size, |
| 1157 | + // but less than 2 * this.chunkSize |
| 1158 | + endByte = this.fileObj.size; |
| 1159 | + } |
| 1160 | + return endByte; |
| 1161 | + } |
| 1162 | + |
1149 | 1163 | /** |
1150 | 1164 | * Chunk end byte in a file |
1151 | 1165 | * @type {number} |
1152 | 1166 | */ |
1153 | | - this.endByte = Math.min(this.fileObj.size, (this.offset + 1) * this.chunkSize); |
| 1167 | + this.endByte = this.computeEndByte(); |
1154 | 1168 |
|
1155 | 1169 | /** |
1156 | 1170 | * XMLHttpRequest |
|
1160 | 1174 |
|
1161 | 1175 | var $ = this; |
1162 | 1176 |
|
1163 | | - |
1164 | 1177 | /** |
1165 | 1178 | * Send chunk event |
1166 | 1179 | * @param event |
|
1284 | 1297 | * @function |
1285 | 1298 | */ |
1286 | 1299 | preprocessFinished: function () { |
1287 | | - // Compute the endByte after the preprocess function to allow an |
| 1300 | + // Re-compute the endByte after the preprocess function to allow an |
1288 | 1301 | // implementer of preprocess to set the fileObj size |
1289 | | - this.endByte = Math.min(this.fileObj.size, (this.offset + 1) * this.chunkSize); |
1290 | | - if (this.fileObj.size - this.endByte < this.chunkSize && |
1291 | | - !this.flowObj.opts.forceChunkSize) { |
1292 | | - // The last chunk will be bigger than the chunk size, |
1293 | | - // but less than 2*this.chunkSize |
1294 | | - this.endByte = this.fileObj.size; |
1295 | | - } |
| 1302 | + this.endByte = this.computeEndByte(); |
| 1303 | + |
1296 | 1304 | this.preprocessState = 2; |
1297 | 1305 | this.send(); |
1298 | 1306 | }, |
|
0 commit comments