nacholibre / node-readlines

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

reset method to reset the pointer to the beginning of the file #5

Closed benishak closed 8 years ago

benishak commented 8 years ago

4

benishak commented 8 years ago

can someone help to fix the error ? why i'm getting Bad Argument from fs.readSync ...

nacholibre commented 8 years ago

I've added reset method in 0.2.4.

benishak commented 8 years ago

I also added close method

https://github.com/nacholibre/node-readlines/pull/5/commits/69e239f412a1439e87e776f24cd52c00ed7b0bf4 https://github.com/nacholibre/node-readlines/pull/5/commits/ca26fe2e4ca71524c4624b67e73a51efbc706555

useful when searching for something in the file to avoid too many open files

while(la = a.next())
    b = new lineByline(path)
    while(lb = b.next())
         if (a.toString() == b.toString()) 
             found <- a.toString
             b.close()
             break
      print found
nacholibre commented 8 years ago

the file is closed when the end is reached, so this close() method is not necessary.

benishak commented 8 years ago

no it is useful, take the following example if you have two files and you want to search for entries from the first file in the 2nd file. you may find it at the middle of the file if you dont close the file you will get too many open files" I close it now in this wayfs.closeSync(file.fd)

while(la = a.next())
    b = new lineByline(path)
    while(lb = b.next())
         if (a.toString() == b.toString()) 
             found <- a.toString
             b.close()
             break
      print found
benishak commented 8 years ago

you should let ppl contribute, not just copy their contribution and commit them as yours!

nacholibre commented 8 years ago

I didn't copy anything, I've just implemented reset method, because you've requested and yours didn't pass the test.. I think I made you a favour.

I will not merge your pull request about the close method, because close method is not necessary.