Как закрыть читаемый поток (до конца)?

Как закрытьчитаемый поток в Node.js?

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

input.on('data', function(data) {
   // after closing the stream, this will not
   // be called again

   if (gotFirstLine) {
      // close this stream and continue the
      // instructions from this if
      console.log("Closed.");
   }
});

Это было бы лучше, чем:

input.on('data', function(data) {
   if (isEnded) { return; }

   if (gotFirstLine) {
      isEnded = true;
      console.log("Closed.");
   }
});

Но это не остановит процесс чтения ...

Ответы на вопрос(9)

Ваш ответ на вопрос