Pausing readline in Node.js

后端 未结 3 966
余生分开走
余生分开走 2020-12-06 01:45

Consider the code below ... I am trying to pause the stream after reading the first 5 lines:

var fs          = require(\'fs\');
var readline    = require(\'r         


        
3条回答
  •  暖寄归人
    2020-12-06 02:07

    So, it turns out that the readline stream tends to "drip" (i.e., leak a few extra lines) even after a pause(). The documentation does not make this clear, but it's true.

    If you want the pause() toggle to appear immediate, you'll have to create your own line buffer and accumulate the leftover lines yourself.

提交回复
热议问题