Read a file one line at a time in node.js?

前端 未结 29 993
深忆病人
深忆病人 2020-11-22 04:33

I am trying to read a large file one line at a time. I found a question on Quora that dealt with the subject but I\'m missing some connections to make the whole thing fit to

29条回答
  •  有刺的猬
    2020-11-22 05:01

    I was frustrated by the lack of a comprehensive solution for this, so I put together my own attempt (git / npm). Copy-pasted list of features:

    • Interactive line processing (callback-based, no loading the entire file into RAM)
    • Optionally, return all lines in an array (detailed or raw mode)
    • Interactively interrupt streaming, or perform map/filter like processing
    • Detect any newline convention (PC/Mac/Linux)
    • Correct eof / last line treatment
    • Correct handling of multi-byte UTF-8 characters
    • Retrieve byte offset and byte length information on per-line basis
    • Random access, using line-based or byte-based offsets
    • Automatically map line-offset information, to speed up random access
    • Zero dependencies
    • Tests

    NIH? You decide :-)

提交回复
热议问题