How to close a readable stream (before end)?

前端 未结 9 1435
名媛妹妹
名媛妹妹 2020-11-29 03:16

How to close a readable stream in Node.js?

var input = fs.createReadStream(\'lines.txt\');

input.on(\'data\', function(data) {
   // after closing the strea         


        
9条回答
  •  悲&欢浪女
    2020-11-29 03:53

    At version 4.*.* pushing a null value into the stream will trigger a EOF signal.

    From the nodejs docs

    If a value other than null is passed, The push() method adds a chunk of data into the queue for subsequent stream processors to consume. If null is passed, it signals the end of the stream (EOF), after which no more data can be written.

    This worked for me after trying numerous other options on this page.

提交回复
热议问题