0
如果我試圖解析包含約20列約100萬行的「大」csv字符串,Papa Parse似乎導致Chrome和Opera崩潰(Windows 7)。在Firefox中成功加載相同頁面的位置。即使在調用Parse之前,Chrome和Opera也會崩潰,前提是我定義了一個大的csv字符串,並將<腳本>標記包含到papaparse.js庫中。如果我不包含papaparse.js的<腳本>標記,創建大型csv字符串沒有問題,但是我無法解析它們。在我的實際使用情況中,我不是在javascript中生成大型csv字符串,而是將它們拉出zip壓縮文件。如果使用步驟或塊功能,似乎沒有任何區別。你可以在這裏運行測試用例。 Test Case 問題代碼;大字符串與Papa解析導致Chrome和Opera崩潰
<!doctype html>
<html>
<script src="http://papaparse.com/resources/js/papaparse.js"></script>
<body>
<script>
function my_createMockCSV(rows) {
var my_csv="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v\r\n";
for (var i=1; i<rows; i++) {
my_csv+= i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+
i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+ i+","+
i+","+ i+","+ i+","+ i+","+ i+","+ i+","+"\r\n";
}
return my_csv;
}
function parseCSV(csv) {
var rowcount=0;
Papa.parse(csv,
{
delimiter: ',',
worker: false,
encoding: 'default',
header: true,
chunk: function(results) {
rowcount+= results.data.length;
console.log("Parsed rows: "+rowcount);
},
complete: function (results) {
console.log("Complete - parsed: "+rowcount+" rows");
}
});
}
function run_testcase() {
rows=document.getElementById("rows").value;
//parseCSV(my_createMockCSV(rows));
console.log("Begin Generating CSV ...");
alert("About to generate Mock CSV");
var my_csv=my_createMockCSV(rows);
console.log("End Generating CSV ...");
alert("About to parse Mock CSV");
parseCSV(my_csv);
}
</script>
Papaparse test case script: Will crash Chrome, Opera<br/>
Rows: <input id="rows" type="number" value="1000000"> (Try around 1mil rows)
<button onclick="run_testcase();">Run</button>
</body>
</html>