@ -1,6 +1,6 @@
/ *
/ *
Papa Parse
Papa Parse
v4 . 0.3
v4 . 0.4
https : //github.com/mholt/PapaParse
https : //github.com/mholt/PapaParse
* /
* /
( function ( global )
( function ( global )
@ -397,7 +397,7 @@
if ( ! config . chunkSize )
if ( ! config . chunkSize )
config . chunkSize = Papa . RemoteChunkSize ;
config . chunkSize = Papa . RemoteChunkSize ;
var start = 0 , fileSize = 0 ;
var start = 0 , fileSize = 0 , rowCount = 0 ;
var aggregate = "" ;
var aggregate = "" ;
var partialLine = "" ;
var partialLine = "" ;
var xhr , url , nextChunk , finishedWithEntireFile ;
var xhr , url , nextChunk , finishedWithEntireFile ;
@ -467,10 +467,10 @@
xhr . open ( "GET" , url , ! IS _WORKER ) ;
xhr . open ( "GET" , url , ! IS _WORKER ) ;
if ( config . step )
if ( config . step || config . chunk )
{
{
var end = start + configCopy . chunkSize - 1 ; // minus one because byte range is inclusive
var end = start + configCopy . chunkSize - 1 ; // minus one because byte range is inclusive
if ( fileSize && end > fileSize ) // Hack around a Chrome bug: http://stackoverflow.com/q/24745095/1048862
if ( fileSize && end > fileSize ) // Hack around a Chrome bug: http://stackoverflow.com/q/24745095/1048862
end = fileSize ;
end = fileSize ;
xhr . setRequestHeader ( "Range" , "bytes=" + start + "-" + end ) ;
xhr . setRequestHeader ( "Range" , "bytes=" + start + "-" + end ) ;
}
}
@ -503,7 +503,7 @@
aggregate += partialLine + xhr . responseText ;
aggregate += partialLine + xhr . responseText ;
partialLine = "" ;
partialLine = "" ;
finishedWithEntireFile = ! config . step || start > getFileSize ( xhr ) ;
finishedWithEntireFile = ( ! config . step && ! config . chunk ) || start > getFileSize ( xhr ) ;
if ( ! finishedWithEntireFile )
if ( ! finishedWithEntireFile )
{
{
@ -528,13 +528,17 @@
var results = handle . parse ( aggregate ) ;
var results = handle . parse ( aggregate ) ;
aggregate = "" ;
aggregate = "" ;
if ( results && results . data )
rowCount += results . data . length ;
var finishedIncludingPreview = finishedWithEntireFile || ( configCopy . preview && rowCount >= configCopy . preview ) ;
if ( IS _WORKER )
if ( IS _WORKER )
{
{
global . postMessage ( {
global . postMessage ( {
results : results ,
results : results ,
workerId : Papa . WORKER _ID ,
workerId : Papa . WORKER _ID ,
finished : finishedWithEntireFile
finished : finishedIncludingPreview
} ) ;
} ) ;
}
}
else if ( isFunction ( config . chunk ) )
else if ( isFunction ( config . chunk ) )
@ -543,10 +547,10 @@
results = undefined ;
results = undefined ;
}
}
if ( finishedWithEntireFile && isFunction ( userComplete ) )
if ( isFunction ( userComplete ) && finishedIncludingPreview )
userComplete ( results ) ;
userComplete ( results ) ;
if ( ! finishedWithEntireFile && ! results . meta . paused )
if ( ! finishedIncludingPreview && ( ! results || ! results . meta . paused ) )
nextChunk ( ) ;
nextChunk ( ) ;
}
}
@ -605,6 +609,7 @@
var slice ;
var slice ;
var aggregate = "" ;
var aggregate = "" ;
var partialLine = "" ;
var partialLine = "" ;
var rowCount = 0 ;
var paused = false ;
var paused = false ;
var self = this ;
var self = this ;
var reader , nextChunk , slice , finishedWithEntireFile ;
var reader , nextChunk , slice , finishedWithEntireFile ;
@ -657,7 +662,7 @@
function nextChunk ( )
function nextChunk ( )
{
{
if ( ! finishedWithEntireFile )
if ( ! finishedWithEntireFile && ( ! configCopy . preview || rowCount < configCopy . preview ) )
readChunk ( ) ;
readChunk ( ) ;
}
}
@ -703,13 +708,17 @@
var results = handle . parse ( aggregate ) ;
var results = handle . parse ( aggregate ) ;
aggregate = "" ;
aggregate = "" ;
if ( results && results . data )
rowCount += results . data . length ;
var finishedIncludingPreview = finishedWithEntireFile || ( configCopy . preview && rowCount >= configCopy . preview ) ;
if ( IS _WORKER )
if ( IS _WORKER )
{
{
global . postMessage ( {
global . postMessage ( {
results : results ,
results : results ,
workerId : Papa . WORKER _ID ,
workerId : Papa . WORKER _ID ,
finished : finishedWithEntireFile
finished : finishedIncludingPreview
} ) ;
} ) ;
}
}
else if ( isFunction ( config . chunk ) )
else if ( isFunction ( config . chunk ) )
@ -720,10 +729,10 @@
results = undefined ;
results = undefined ;
}
}
if ( finishedWithEntireFile && isFunction ( userComplete ) )
if ( isFunction ( userComplete ) && finishedIncludingPreview )
userComplete ( results ) ;
userComplete ( results ) ;
if ( ! results || ! results . meta . paused )
if ( ! finishedIncludingPreview && ( ! results || ! results . meta . paused ) )
nextChunk ( ) ;
nextChunk ( ) ;
}
}