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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章