Skip to content

Commit 6052203

Browse files
committed
Address bug discussed on #155
1 parent 900dc25 commit 6052203

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/flow.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,11 +1146,25 @@
11461146
*/
11471147
this.startByte = this.offset * this.chunkSize;
11481148

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+
11491163
/**
11501164
* Chunk end byte in a file
11511165
* @type {number}
11521166
*/
1153-
this.endByte = Math.min(this.fileObj.size, (this.offset + 1) * this.chunkSize);
1167+
this.endByte = this.computeEndByte();
11541168

11551169
/**
11561170
* XMLHttpRequest
@@ -1160,7 +1174,6 @@
11601174

11611175
var $ = this;
11621176

1163-
11641177
/**
11651178
* Send chunk event
11661179
* @param event
@@ -1284,15 +1297,10 @@
12841297
* @function
12851298
*/
12861299
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
12881301
// 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+
12961304
this.preprocessState = 2;
12971305
this.send();
12981306
},

0 commit comments

Comments
 (0)