Skip to content

Commit ec50b09

Browse files
committed
Merge pull request #112 from Veabers/master
fix: preproccess pause/resume for issue #108
2 parents 321a25b + 01dde96 commit ec50b09

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

src/flow.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,13 @@
295295
if (this.opts.prioritizeFirstAndLastChunk) {
296296
each(this.files, function (file) {
297297
if (!file.paused && file.chunks.length &&
298-
file.chunks[0].status() === 'pending' &&
299-
file.chunks[0].preprocessState === 0) {
298+
file.chunks[0].status() === 'pending') {
300299
file.chunks[0].send();
301300
found = true;
302301
return false;
303302
}
304303
if (!file.paused && file.chunks.length > 1 &&
305-
file.chunks[file.chunks.length - 1].status() === 'pending' &&
306-
file.chunks[0].preprocessState === 0) {
304+
file.chunks[file.chunks.length - 1].status() === 'pending') {
307305
file.chunks[file.chunks.length - 1].send();
308306
found = true;
309307
return false;
@@ -318,7 +316,7 @@
318316
each(this.files, function (file) {
319317
if (!file.paused) {
320318
each(file.chunks, function (chunk) {
321-
if (chunk.status() === 'pending' && chunk.preprocessState === 0) {
319+
if (chunk.status() === 'pending') {
322320
chunk.send();
323321
found = true;
324322
return false;

test/uploadSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,30 @@ describe('upload file', function() {
431431
expect(preprocess).wasNotCalledWith(secondFile.chunks[0]);
432432
});
433433

434+
it('should resume preprocess chunks after pause', function () {
435+
flow.opts.chunkSize = 1;
436+
flow.opts.simultaneousUploads = 1;
437+
flow.opts.testChunks = false;
438+
var preprocess = jasmine.createSpy('preprocess');
439+
var error = jasmine.createSpy('error');
440+
var success = jasmine.createSpy('success');
441+
flow.on('fileError', error);
442+
flow.on('fileSuccess', success);
443+
flow.opts.preprocess = preprocess;
444+
flow.addFile(new Blob(['abc']));
445+
var file = flow.files[0];
446+
flow.upload();
447+
for(var i=0; i<file.chunks.length; i++) {
448+
expect(preprocess).wasCalledWith(file.chunks[i]);
449+
file.chunks[i].preprocessFinished();
450+
file.pause();
451+
file.resume();
452+
requests[requests.length-1].respond(200, [], "response");
453+
}
454+
expect(success).wasCalledWith(file, "response", file.chunks[file.chunks.length-1]);
455+
expect(error).not.toHaveBeenCalled();
456+
});
457+
434458
it('should set chunk as a third event parameter', function () {
435459
var success = jasmine.createSpy('success');
436460
flow.on('fileSuccess', success);

0 commit comments

Comments
 (0)