Jak zamknąć czytelny strumień (przed końcem)?
Jak zamknąć aczytelny strumień w 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.");
}
});
Byłoby to lepsze niż:
input.on('data', function(data) {
if (isEnded) { return; }
if (gotFirstLine) {
isEnded = true;
console.log("Closed.");
}
});
Ale to nie zatrzymałoby procesu czytania ...