Skip to content

Commit 187c372

Browse files
authored
Update flow.js
1 parent fc6c242 commit 187c372

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/flow.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Flow.js is a library providing multiple simultaneous, stable and
1313
* resumable uploads via the HTML5 File API.
1414
* @param [opts]
15-
* @param {number} [opts.chunkSize]
15+
* @param {number|Function} [opts.chunkSize]
1616
* @param {bool} [opts.forceChunkSize]
1717
* @param {number} [opts.simultaneousUploads]
1818
* @param {bool} [opts.singleFile]
@@ -79,7 +79,6 @@
7979
*/
8080
this.defaults = {
8181
chunkSize: 1024 * 1024,
82-
calculateChunkSize: null,
8382
forceChunkSize: false,
8483
simultaneousUploads: 3,
8584
singleFile: false,
@@ -751,6 +750,12 @@
751750
* @type {string}
752751
*/
753752
this.uniqueIdentifier = (uniqueIdentifier === undefined ? flowObj.generateUniqueIdentifier(file) : uniqueIdentifier);
753+
754+
/**
755+
* Size of Each Chunk
756+
* @type {number}
757+
*/
758+
this.chunkSize = 0;
754759

755760
/**
756761
* List of chunks
@@ -939,13 +944,9 @@
939944
// Rebuild stack of chunks from file
940945
this._prevProgress = 0;
941946
var round = this.flowObj.opts.forceChunkSize ? Math.ceil : Math.floor;
942-
var calculateChunkSize = this.flowObj.opts.calculateChunkSize;
943-
var chunkSize = this.flowObj.opts.chunkSize;
944-
if (typeof calculateChunkSize === 'function') {
945-
chunkSize = calculateChunkSize(this);
946-
}
947+
this.chunkSize = evalOpts(this.flowObj.opts.chunkSize, this);
947948
var chunks = Math.max(
948-
round(this.size / chunkSize), 1
949+
round(this.size / this.chunkSize), 1
949950
);
950951
for (var offset = 0; offset < chunks; offset++) {
951952
this.chunks.push(
@@ -1159,7 +1160,7 @@
11591160
* Size of a chunk
11601161
* @type {number}
11611162
*/
1162-
this.chunkSize = this.flowObj.opts.chunkSize;
1163+
this.chunkSize = this.fileObj.chunkSize;
11631164

11641165
/**
11651166
* Chunk start byte in a file
@@ -1273,7 +1274,7 @@
12731274
getParams: function () {
12741275
return {
12751276
flowChunkNumber: this.offset + 1,
1276-
flowChunkSize: this.flowObj.opts.chunkSize,
1277+
flowChunkSize: this.chunkSize,
12771278
flowCurrentChunkSize: this.endByte - this.startByte,
12781279
flowTotalSize: this.fileObj.size,
12791280
flowIdentifier: this.fileObj.uniqueIdentifier,

0 commit comments

Comments
 (0)