|
|
|
;(function(e){"use strict";function u(e,r){var i=t?r:g(r);var s=i.worker&&Papa.WORKERS_SUPPORTED&&n;if(s){var o=d();o.userStep=i.step;o.userChunk=i.chunk;o.userComplete=i.complete;o.userError=i.error;i.step=b(i.step);i.chunk=b(i.chunk);i.complete=b(i.complete);i.error=b(i.error);delete i.worker;o.postMessage({input:e,config:i,workerId:o.id})}else{if(typeof e==="string"){if(i.download){var u=new f(i);u.stream(e)}else{var a=new c(i);var h=a.parse(e);return h}}else if(e instanceof File){if(i.step||i.chunk){var u=new l(i);u.stream(e)}else{var a=new c(i);if(t){var p=new FileReaderSync;var v=p.readAsText(e,i.encoding);return a.parse(v)}else{p=new FileReader;p.onload=function(e){var t=new c(i);var n=t.parse(e.target.result)};p.onerror=function(){if(b(i.error))i.error(p.error,e)};p.readAsText(e,i.encoding)}}}}}function a(t,n){function a(){if(typeof n!=="object")return;if(typeof n.delimiter==="string"&&n.delimiter.length==1&&e.Papa.BAD_DELIMITERS.indexOf(n.delimiter)==-1){o=n.delimiter}if(typeof n.quotes==="boolean"||n.quotes instanceof Array)s=n.quotes;if(typeof n.newline==="string")u=n.newline}function f(e){if(typeof e!=="object")return[];var t=[];for(var n in e)t.push(n);return t}function l(e,t){var n="";if(typeof e==="string")e=JSON.parse(e);if(typeof t==="string")t=JSON.parse(t);var r=e instanceof Array&&e.length>0;var i=!(t[0]instanceof Array);if(r){for(var s=0;s<e.length;s++){if(s>0)n+=o;n+=c(e[s],s)}if(t.length>0)n+=u}for(var a=0;a<t.length;a++){var f=r?e.length:t[a].length;for(var l=0;l<f;l++){if(l>0)n+=o;var h=r&&i?e[l]:l;n+=c(t[a][h],l)}if(a<t.length-1)n+=u}return n}function c(t,n){if(typeof t==="undefined"||t===null)return"";t=t.toString().replace(/"/g,'""');var r=typeof s==="boolean"&&s||s instanceof Array&&s[n]||h(t,e.Papa.BAD_DELIMITERS)||t.indexOf(o)>-1||t.charAt(0)==" "||t.charAt(t.length-1)==" ";return r?'"'+t+'"':t}function h(e,t){for(var n=0;n<t.length;n++)if(e.indexOf(t[n])>-1)return true;return false}var r="";var i=[];var s=false;var o=",";var u="\r\n";a();if(typeof t==="string")t=JSON.parse(t);if(t instanceof Array){if(!t.length||t[0]instanceof Array)return l(null,t);else if(typeof t[0]==="object")return l(f(t[0]),t)}else if(typeof t==="object"){if(typeof t.data==="string")t.data=JSON.parse(t.data);if(t.data instanceof Array){if(!t.fields)t.fields=t.data[0]instanceof Array?t.fields:f(t.data[0]);if(!(t.data[0]instanceof Array)&&typeof t.data[0]!=="object")t.data=[t.data]}return l(t.fields||[],t.data||[])}throw"exception: Unable to serialize unrecognized input"}function f(n){function v(){if(l){m();return}u=new XMLHttpRequest;if(!t){u.onload=m;u.onerror=g}u.open("GET",a,!t);if(n.step){var e=r+d.chunkSize-1;if(i&&e>i)e=i;u.setRequestHeader("Range","bytes="+r+"-"+e)}try{u.send()}catch(s){g(s.message)}if(t&&u.status==0)g();else r+=d.chunkSize}function m(){if(u.readyState!=4)return;if(u.status<200||u.status>=400){g();return}s+=o+u.responseText;o="";l=!n.step||r>w(u);if(!l){var i=s.lastIndexOf("\r");if(i==-1)i=s.lastIndexOf("\n");if(i!=-1){o=s.substring(i+1);s=s.substring(0,i)}else{f();return}}var a=p.parse(s);s="";if(t){e.postMessage({results:a,workerId:Papa.WORKER_ID,finished:l})}else if(b(n.chunk)){n.chunk(a,p);a=undefined}if(l&&b(h))h(a);if(!l&&!a.meta.paused)f()}function g(r){var i=u.statusText||r;if(b(n.error))n.error(i);else if(t&&n.error){e.postMessage({workerId:Papa.WORKER_ID,error:i,finished:false})}}function w(e){var t=e.getResponseHeader("Content-Range");return parseInt(t.substr(t.lastIndexOf("/")+1))}function E(e){d=y(e);h=d.complete;d.complete=undefined;d.chunkSize=parseInt(d.chunkSize);p=new c(d);p.streamer=this}n=n||{};if(!n.chunkSize)n.chunkSize=Papa.RemoteChunkSize;var r=0,i=0;var s="";var o="";var u,a,f,l;var h,p,d;E(n);this.resume=function(){paused=false;f()};this.finished=function(){return l};this.pause=function(){paused=true};this.abort=function(){l=true;if(b(h))h({data:[],errors:[],meta:{aborted:true}})};this.stream=function(e){a=e;if(t){f=function(){v();m()}}else{f=function(){v()}}f()}}function l(n){function h(){if(!p)w()}function w(){var e=Math.min(r+m.chunkSize,i.size);var t=l.readAsText(
|