|
12 | 12 | * Flow.js is a library providing multiple simultaneous, stable and
|
13 | 13 | * resumable uploads via the HTML5 File API.
|
14 | 14 | * @param [opts]
|
15 |
| - * @param {number} [opts.chunkSize] |
| 15 | + * @param {number|Function} [opts.chunkSize] |
16 | 16 | * @param {bool} [opts.forceChunkSize]
|
17 | 17 | * @param {number} [opts.simultaneousUploads]
|
18 | 18 | * @param {bool} [opts.singleFile]
|
|
79 | 79 | */
|
80 | 80 | this.defaults = {
|
81 | 81 | chunkSize: 1024 * 1024,
|
82 |
| - calculateChunkSize: null, |
83 | 82 | forceChunkSize: false,
|
84 | 83 | simultaneousUploads: 3,
|
85 | 84 | singleFile: false,
|
|
751 | 750 | * @type {string}
|
752 | 751 | */
|
753 | 752 | this.uniqueIdentifier = (uniqueIdentifier === undefined ? flowObj.generateUniqueIdentifier(file) : uniqueIdentifier);
|
| 753 | + |
| 754 | + /** |
| 755 | + * Size of Each Chunk |
| 756 | + * @type {number} |
| 757 | + */ |
| 758 | + this.chunkSize = 0; |
754 | 759 |
|
755 | 760 | /**
|
756 | 761 | * List of chunks
|
|
939 | 944 | // Rebuild stack of chunks from file
|
940 | 945 | this._prevProgress = 0;
|
941 | 946 | 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); |
947 | 948 | var chunks = Math.max(
|
948 |
| - round(this.size / chunkSize), 1 |
| 949 | + round(this.size / this.chunkSize), 1 |
949 | 950 | );
|
950 | 951 | for (var offset = 0; offset < chunks; offset++) {
|
951 | 952 | this.chunks.push(
|
|
1159 | 1160 | * Size of a chunk
|
1160 | 1161 | * @type {number}
|
1161 | 1162 | */
|
1162 |
| - this.chunkSize = this.flowObj.opts.chunkSize; |
| 1163 | + this.chunkSize = this.fileObj.chunkSize; |
1163 | 1164 |
|
1164 | 1165 | /**
|
1165 | 1166 | * Chunk start byte in a file
|
|
1273 | 1274 | getParams: function () {
|
1274 | 1275 | return {
|
1275 | 1276 | flowChunkNumber: this.offset + 1,
|
1276 |
| - flowChunkSize: this.flowObj.opts.chunkSize, |
| 1277 | + flowChunkSize: this.chunkSize, |
1277 | 1278 | flowCurrentChunkSize: this.endByte - this.startByte,
|
1278 | 1279 | flowTotalSize: this.fileObj.size,
|
1279 | 1280 | flowIdentifier: this.fileObj.uniqueIdentifier,
|
|
0 commit comments