Browse Source

remove references to streamer._paused and fix fake chunk callbacks

pull/481/head
Braden Anderson 10 years ago committed by Sergi Almacellas Abellana
parent
commit
86c37d6108
  1. 9
      papaparse.js
  2. 66
      tests/test-cases.js

9
papaparse.js

@ -424,7 +424,6 @@
function ChunkStreamer(config) function ChunkStreamer(config)
{ {
this._handle = null; this._handle = null;
this._paused = false;
this._finished = false; this._finished = false;
this._input = null; this._input = null;
this._baseIndex = 0; this._baseIndex = 0;
@ -440,7 +439,7 @@
}; };
replaceConfig.call(this, config); replaceConfig.call(this, config);
this.parseChunk = function(chunk) this.parseChunk = function(chunk, isFakeChunk)
{ {
// First chunk pre-processing // First chunk pre-processing
if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk)) if (this.isFirstChunk && isFunction(this._config.beforeFirstChunk))
@ -481,10 +480,10 @@
finished: finishedIncludingPreview finished: finishedIncludingPreview
}); });
} }
else if (isFunction(this._config.chunk)) else if (isFunction(this._config.chunk) && !isFakeChunk)
{ {
this._config.chunk(results, this._handle); this._config.chunk(results, this._handle);
if (this._paused) if (this._handle.paused())
return; return;
results = undefined; results = undefined;
this._completeResults = undefined; this._completeResults = undefined;
@ -916,7 +915,7 @@
this.resume = function() this.resume = function()
{ {
_paused = false; _paused = false;
self.streamer.parseChunk(_input); self.streamer.parseChunk(_input, true);
}; };
this.aborted = function () this.aborted = function ()

66
tests/test-cases.js

@ -1564,6 +1564,72 @@ var CUSTOM_TESTS = [
}); });
} }
}, },
{
description: "Chunk functions can pause parsing",
expected: [
[['A', 'b', 'c']]
],
run: function(callback) {
var updates = [];
Papa.parse('A,b,c\nd,E,f\nG,h,i', {
chunkSize: 10,
chunk: function(response, handle) {
updates.push(response.data);
handle.pause();
callback(updates);
},
complete: function() {
callback('incorrect complete callback');
}
});
}
},
{
description: "Chunk functions can resume parsing",
expected: [
[['A', 'b', 'c']],
[['d', 'E', 'f'], ['G', 'h', 'i']]
],
run: function(callback) {
var updates = [];
var handle = null;
var first = true;
Papa.parse('A,b,c\nd,E,f\nG,h,i', {
chunkSize: 10,
chunk: function(response, h) {
updates.push(response.data);
if (!first) return;
handle = h;
handle.pause();
first = false;
},
complete: function() {
callback(updates);
}
});
setTimeout(function() {
handle.resume();
}, 500);
}
},
{
description: "Chunk functions can abort parsing",
expected: [
[['A', 'b', 'c'], ['d', 'E', 'f'], ['G', 'h', 'i']]
],
run: function(callback) {
var updates = [];
Papa.parse('A,b,c\nd,E,f\nG,h,i', {
chunk: function(response, handle) {
updates.push(response.data);
handle.abort();
},
complete: function(response) {
callback(updates);
}
});
}
},
{ {
description: "Step exposes indexes for files", description: "Step exposes indexes for files",
expected: [6, 12, 17], expected: [6, 12, 17],

Loading…
Cancel
Save