Skip to content

compare files of different length #5

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

Open
joh-klein opened this issue Aug 23, 2022 · 4 comments
Open

compare files of different length #5

joh-klein opened this issue Aug 23, 2022 · 4 comments

Comments

@joh-klein
Copy link

I really like this package! Thanks for your hard work!

What I wish it could do: when one file is longer (has more lines) than the other, that it doesn't stop but append all the missing lines to the output (either as being new (+) or old (-) )

@noogen
Copy link
Contributor

noogen commented Aug 23, 2022

You can use compared event to detect end of file, see parameters here: https://github.com/niiknow/text-file-diff/blob/master/src/index.ts#L104

End of file property, ref: https://github.com/niiknow/text-file-diff/blob/master/src/index.ts#L15

const lfd = new TextFileDiff({
  skipHeader: argv.skipHeader
});

lfd.on('compared', (line1, line2, cmpar, lineReader1, lineReader2) => {
  if (lineReader1.eof > -1 || lineReader2.eof > -1) {
      // do something such as exit program, etc...
  }
});

The plus (+) and minus (-) events also receive lineReader1 and lineReader2 as 2nd and 3rd parameter so you can also detect end of file within those events, ref: https://github.com/niiknow/text-file-diff/blob/master/src/index.ts#L111

@ctf0
Copy link

ctf0 commented Jan 10, 2023

@noogen am kinda in the same boat, can u plz elaborate how to actually use that ?

for example, lets say the first-stream lines count is 40, while the second stream lines count is 50, how do u get the diff ?

@noogen
Copy link
Contributor

noogen commented Jan 11, 2023

@ctf0 I don't understand, it already doing that. Have you tried it? Elaborate more on what are you really expect it to do?

Even better, look at the unit tests. Fork, upload your 2 files, write unit tests and elaborate on what you're expecting it to do. Do the real Test Driven Development (TDD) approach.

@ctf0
Copy link

ctf0 commented Jan 12, 2023

oh, my bad, i got it totally wrong, thanks again

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

3 participants