Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get maximun lines of the file #23

Open
masalinas opened this issue Feb 26, 2018 · 2 comments
Open

Get maximun lines of the file #23

masalinas opened this issue Feb 26, 2018 · 2 comments

Comments

@masalinas
Copy link

masalinas commented Feb 26, 2018

How can I get the number of lines of the file with your library?

@adadgio
Copy link

adadgio commented Jan 13, 2019

Up ! Agree that would be super useful, because there is currently no way to known when the end of file has been reached

@adadgio
Copy link

adadgio commented Jan 13, 2019

I found a way by wrapping into a promise and declare a global variable that you can increment. Code is bellow (ts).

let maxLines: number = 0

return new Promise((resolve, reject) => {
    rl.on('line', (line, lineCount, byteCount) => {
        maxLines = lineCount
        // here i am looking for a string, and... 
       // ... if blahbla => resolve promise
    })
    .on('end', () => {
        console.log('End of file reached', maxLines)
    })
    .on('error', (err) => {
        reject(err)
    })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants