node.js: read a text file into an array. (Each line an item in the array.)

问题:

I would like to read a very, very large file into a JavaScript array in node.js.我想将一个非常非常大的文件读入 node.js 中的 JavaScript 数组。

So, if the file is like this:所以,如果文件是这样的:

first line
two 
three
...
...

I would have the array:我会有数组:

['first line','two','three', ... , ... ] 

The function would look like this:该函数如下所示:

var array = load(filename); 

Therefore the idea of loading it all as a string and then splitting it is not acceptable.因此,将其全部加载为字符串然后将其拆分的想法是不可接受的。


解决方案:

参考一: https://en.stackoom.com/question/SfIE
参考二: https://stackoom.com/question/SfIE
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章