nacholibre / node-readlines

Read large text files line by line (synchronous) for Node.js
MIT License
161 stars 28 forks source link

Close file? #16

Closed whoyawn closed 6 years ago

whoyawn commented 6 years ago

Hi, thanks for the library. It seems like there was no manual close function. I tried to write it myself, but ended up with this error

fs.js:629
  return binding.close(fd);

TypeError: fd must be a file descriptor

Thought it would be as simple as

LineByLine.prototype.close = function() {
  fs.closeSync(this.fd);
  this.fd = null;
}

but it's not :(

Any pointers on how to go about this?

nacholibre commented 6 years ago

This means it's already closed, because I set fd to null when it's closed.

whoyawn commented 6 years ago

However, I get an error once I read around 23 files that I have too many files open. Somehow they're actually not closing.

nacholibre commented 6 years ago

Are you sure this is the problem? Only 23 files and you get too many open files? What OS are you using?

whoyawn commented 6 years ago

I'm unable to access the computer that I ran it on as of now, sorry. It was on High Sierra 10.13.3 nodejs 8.5. Now I'm running the same code on Sierra 10.12.6 nodejs 8.5 and it works fine. I can just close this until I can confidently replicate it.