到目前为止,我的文件阅读器 api 代码一直运行良好,直到有一天我从我的一位客户那里得到了一个 280MB 的 txt 文件。页面在 Chrome 中直接崩溃,在 Firefox 中没有任何react。
// create new reader object 
var fileReader = new FileReader(); 
// read the file as text 
fileReader.readAsText( $files[i] );  
fileReader.onload = function(e) 
{   // read all the information about the file 
    // do sanity checks here etc... 
    $timeout( function() 
    {    
        // var fileContent = e.target.result;
        // get the first line 
        var firstLine = e.target.result.slice(0, e.target.result.indexOf("\n") ); }}
我在上面尝试做的是获取第一个换行符,以便我可以获得文件的列长度。我不应该把它作为文本阅读吗?如何在不破坏大文件页面的情况下获取文件的列长度?