到目前为止,我的文件阅读器api代码一直运行良好,直到有一天我从我的一个客户端获得了一个280MB的txt文件.页面只是在Chrome中直接崩溃,在Firefox中没有任何反应.
// 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") ); }}
Run Code Online (Sandbox Code Playgroud)
我上面要做的是获取第一个换行符,以便我可以获得文件的列长度.我不应该把它看作文字吗?如何在不破坏大文件页面的情况下获取文件的列长度?